I mean:
'string'.try :inexistent_method
yields an error...
Thanks in advance,
Rodrigo.
When you use Active Model standalone, you need to cherry-pick the
Active Support core extensions you wish to use:
require 'active_support/core_ext/object/try'
Or, to use them all:
require 'active_support/all'
jeremy
Actually I'll avoid using try since I am writing a patch to ActiveModel
and it seems that ActiveModel should not depend on ActiveSupport, right?
I'm writing this pattern, instead: "foo = bar.inexistent_method if
bar.responds_to? :inexistent_method"
I'm a bit confuse about how to add a :full_message option to validations
without breaking backward compatibilities... Subclassing String doesn't
seem to be easy.
I'm inclined to do something like 'string'.extend SomeHelperClass and
:symbol.extend SomeHelperClass...
Have a good new year!
Best regards,
Rodrigo.
I'm not sure why you'd need to subclass string to add a full_message
option to validations? Could you explain how you were planning on
doing this?
Active Model does depend on Active Support, but it cherry-picks just
what it needs rather than including the whole enchilada. So you're
free to use the try extension.
jeremy
Mateo, I did not answer you before because I wanted to finish my attempt
and show it instead of talk about it.
Follows a patch in attachment (still missing tests and documentation) to
illustrate my idea.
If you think that could be accepted, I will add the tests, documentation
and will probably require the 'try' from active_support for better
readability.
What do you think?
Anyway, I want to wish all rails-core list members a happy new year!
Best regards,
Rodrigo.
I ended up giving up on this approach and only included a "full_message"
state on the validation.
I also has learned a bit more about Ruby... What would you expect from
the following snippet?
class NewString < String
def initialize(options={})
end
def to_s
options[:message]
end
end
puts NewString.new(:message => 'Hi')
I expected it would be 'Hi', but it is actually nil. :)
Thank you for your interest,
Rodrigo.
--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group.
To post to this group, send email to rubyonra...@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-co...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-core?hl=en.
class NewString < String
attr_reader :options
def initialize(options={})
@options = options
end
def to_s
options[:message]
end
end
Did you try your example?
It didn't work here...
> <mailto:rubyonra...@googlegroups.com>.
> To unsubscribe from this group, send email to
> rubyonrails-co...@googlegroups.com
> <mailto:rubyonrails-core%2Bunsu...@googlegroups.com>.
print (which is called by puts) only calls to_s on objects that are
not strings. You might get this to work by implementing a different
method, but I'm not sure subclassing is the right way to go about this
in the first place...
What I didn't find was an instruction about how to subclass a String....
Did someone already tried this out?
Best regards,
Rodrigo.