This project is archived and is in readonly mode.
attr_accesor_with_default alias reader method
-
Aditya Sanghi
- Importance changed from to Low
@bhu, it is indeed odd and I can reproduce this behavior.
I don't think it was not how it was intended but unfortunately this is how the functionality got implemented.
The writer redefines the reader to clear out the default.I wish it was written a bit more cleanly such that reader and writers were only defined once.
something like (pseudocode)
def sym=(value) @sym_marked = true @sym = value end def sym @sym_marked ? @sym : default_value # default_value would return the default value or invoke the block endFeel free to implement and patch.
-
bhu
Hmm i can't upload the diff file. Am i doing something wrong?
-
bhu
tried patch tags, state:resolved, patch prefix, patch/diff file extensions.
I used the sending_patches guide.
There is no error message. Every time I try to attach a file, nothing happens after submitting.
Sorry for making it unnecessary complicated. -
Aditya Sanghi
Try putting it in a gist. I'll try to upload the patch here. Sorry for the delay.
-
bhu
Here my latest version in case of tagging.
https://gist.github.com/748873
Hopefully you can tell me what i did wrong.I hope you like the solution with the additional method.
If there are any problems please inform me. First ticket so i don't really know if i did everything right.
The "(@sym_marked ||= false)" is just to get rid of uninitialized variable warning.
-
Aditya Sanghi
- State changed from new to open
- Tag set to patch
-
rails
This issue has been automatically marked as stale because it has not been commented on for at least three months.
The resources of the Rails core team are limited, and so we are asking for your help. If you can still reproduce this error on the 3-0-stable branch or on master, please reply with all of the information you have about it and add "[state:open]" to your comment. This will reopen the ticket for review. Likewise, if you feel that this is a very important feature for Rails to include, please reply with your explanation so we can consider it.
Thank you for all your contributions, and we hope you will understand this step to focus our efforts where they are most helpful.
-
rails
- State changed from open to stale
-
bhu
- State changed from stale to open
The in my eyes error still exists in 3.0.5. The diff is also included with the tests. The ticket just needs to be reviewed, or did i miss something? I think this could be an cleaner an better useable solution than the old version. [state:open]
