I am trying to use a dynamic method after the dot operator, its not identifying. Please help me in resolving this is an urgent issue. @opt1 has already a method which is same as the def_name assigned value def_name = field_details.downcase.tr('-', '') @opt1.def_name = details['fieldvalue'] Please help...... Thanks, Sai
on 2017-04-04 13:16
on 2017-04-05 10:09
I'm not sure whether I understand your question correctly. Let's do an example: Assuming that def_name evaluates to the String 'foo', is it correct that @opt1 understands a @opt1.foo = .... ? In this case, you can do it like this: @opt1.send_public((def_name+'=').to_sym, details['fieldvalue']) Ronald
on 2017-04-06 06:57
I have no real idea what you are trying to do here but: > def_name = field_details.downcase.tr('-', '') > @opt1.def_name = details['fieldvalue'] Do you try to dynamically call a method? In this case you could try to use .send(). I do not understand why you show only two lines of code. Errors could be elsewhere in your code. Always try to showcase the smallest part of where the problem is AND the specific error too.
on 2017-04-06 10:54
@Robert: I admit that the OPs question is a bit unclear, but I assume that he wants to invoke a setter method where he has the name of the corresponding getter method as a string. I would recommend against using Object#send, as you suggested, but use Object#public_send instead. It's safer. Ooops, I see that in my own response, I misspelled the method name. Will fix it.
on 2017-04-06 10:55
Just a notice (because I can't edit my earlier posting anymore): The method you need to invoke is 'public_send', not 'send_public', as I wrote. Sorry for the confusing typo. Ronald
on 2017-04-07 08:40
Sai Charan wrote in post #1185750: > I am trying to use a dynamic method after the dot operator, its not > identifying. Please help me in resolving this is an urgent issue. > > @opt1 has already a method which is same as the def_name assigned value > > > def_name = field_details.downcase.tr('-', '') > @opt1.def_name = details['fieldvalue'] > > > Please help...... > > Thanks, > Sai I'm not trying to be sarcastic, just passing along a very useful tool. I usually just put Ruby, Class, Datatype" into Google and the appropriate rubydoc pops up This is very handy. https://www.sagipl.com/ruby-on-rails-development/
on 2017-04-07 16:55
Thanks a lot guys figured out a way screen.method(method_name).call(field_value) This has worked