Hello Nathan, thanks for taking a crack at this.
I have already tried your first suggestion here. The trouble is that
this pattern (def val=; raise “”; end) prevents the attribute from
ever being written to, even from within the model itself.
attr_reader and “private ‘val=’” approaches in core ruby prevent
setting the attribute from outside of the class, but allow it from
within the class. I really do need to allow control over the attribute
from within the class. In the “initialize” method for example, or when
counters internally increment, or cached values internally need to be
If I have to I will look up how “attr_reader” is implemented and
override that for ActiveRecord::Base and offer that as a plugin or a
patch. But I just wanted to make sure that:
A> this isn’t already somehow available a different way, and
B> It’s a popular enough option.
If this is not a popular pattern there must be a good reason; my view
of the world may likely be out of whack. If it is a popular pattern
I’m amazed it isn’t already available. Solomon’s adage “There is
nothing new under the sun” really, really ought to apply here. If I
have to write a new patch or plugin 3 hours into my first serious Ruby
project, I’ve got to be overlooking something or leaving The Path
somehow. I mean, who am I to find one of the most fundamental concepts
from OOP 101 (private attribute setters) missing in the world’s most
popular web framework, built upon the most zealously object oriented
language since SmallTalk? I’ve got to be looking at something wrongly
I’ve asked about this in irc with no more luck there. All I know is if
I spend a day or two perfecting a patch or plugin, and only then does
someone say “look, all you really should have done is (2 arbitrary
lines of code)”, I’ll go clinically mad. Also, should I ever be found
meddling in such deep affairs if nobody else seems interested in this
Does my problem, and/or my paranoia about taking apart the engine to
fix it, make any sense to anyone else here?
TIA for your wisdom!
- Jesse Thompson
Webformix, Bend OR
On Jun 9, 3:51 am, Nathan E. [email protected]