This project is archived and is in readonly mode.
attr_accesor_with_default alias reader method
Reported by bhu | December 2nd, 2010 @ 02:54 AM
attr_accessor_with_default :something_processed, false
alias_method :something_processed?, :something_processed
seems to be a problem because the reader looks like it is
redefined on line 26 in "attr_accessor_with_default.rb"
class << self; attr_reader :#{sym} end # class << self; attr_reader :age end
x = Blubb.new
x.something_processed # => false
x.something_processed? # => false
x.something_processed = true # => true
x.something_processed # => true
x.something_processed? # => false
imho the last line should also return true
i'm sorry if that behavior is how it's intended
Comments and changes to this ticket
-
Aditya Sanghi December 2nd, 2010 @ 08:31 AM
- 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 end
Feel free to implement and patch.
-
bhu December 12th, 2010 @ 05:07 PM
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 December 20th, 2010 @ 07:14 PM
Try putting it in a gist. I'll try to upload the patch here. Sorry for the delay.
-
bhu December 20th, 2010 @ 07:43 PM
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 December 20th, 2010 @ 09:24 PM
- no changes were found...
-
Aditya Sanghi December 20th, 2010 @ 09:24 PM
- State changed from new to open
- Tag set to patch
-
rails March 21st, 2011 @ 12:00 AM
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 March 21st, 2011 @ 12:00 AM
- State changed from open to stale
-
bhu March 21st, 2011 @ 09:23 AM
- 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]
Create your profile
Help contribute to this project by taking a few moments to create your personal profile. Create your profile »
<h2 style="font-size: 14px">Tickets have moved to Github</h2>
The new ticket tracker is available at <a href="https://github.com/rails/rails/issues">https://github.com/rails/rails/issues</a>