How to strip() all instance var of class instance?

26 views
Skip to first unread message

j...@via.net

unread,
Jul 2, 2015, 12:21:51 AM7/2/15
to rubyonra...@googlegroups.com

Something like x.instance_variables.each.... { |i} .... }

Ought to be a one liner. I can't figure out how to apply strip() to each variable, since instance_variable_get returns the value. I really want something I can apply .strip! to....

Frederick Cheung

unread,
Jul 2, 2015, 2:19:54 AM7/2/15
to rubyonra...@googlegroups.com, j...@via.net
On Thursday, July 2, 2015 at 5:21:51 AM UTC+1, j...@via.net wrote:
> Something like x.instance_variables.each.... { |i} .... }
>
>
> Ought to be a one liner. I can't figure out how to apply strip() to each variable, since instance_variable_get returns the value. I really want something I can apply .strip! to....

What make you think you can't do that to the result from instance_variable_get ?

Fred

j...@via.net

unread,
Jul 2, 2015, 2:06:58 PM7/2/15
to rubyonra...@googlegroups.com
You are correct - this works. But, why? Doesn't instance_variable_get  return the value of a variable, not the actual variable itself?

Frederick Cheung

unread,
Jul 2, 2015, 4:46:12 PM7/2/15
to rubyonra...@googlegroups.com, j...@via.net
On Thursday, July 2, 2015 at 7:06:58 PM UTC+1, j...@via.net wrote:
> You are correct - this works. But, why? Doesn't instance_variable_get  return the value of a variable, not the actual variable itself?
>

instance_variable_get(:@foo) evaluates exactly the same object as @foo.

Fred
Reply all
Reply to author
Forward
0 new messages