On Fri, Mar 7, 2014 at 3:43 PM, Dave Aronson
<ruby-talk.list.2.TRex / codosaur.us> wrote:
> On Fri, Mar 7, 2014 at 3:51 PM, Kape Kape <lists / ruby-forum.com> wrote:
>
>> When I do:
>>
>> ab4435 = MyClassFoo.new(blah)
>>
>> I want to get instance variable name 'ab4435' inside the class for use
>> in a methods.
> ...
>> What's the ruby way to do this?
>
> I think most of us would discourage such opaque trickery, but if you
> really Really REALLY need to, I think I would do something like:
>
> Declare a method that takes a parameter of a symbol, passes the symbol
> to the constructor, and uses the symbol to set an instance variable to
> the resulting value with instance_variable_set.  Then invoke it like
> "make_foo :bar" to do the equivalent of "bar = MyClassFoo.new(:bar,
> &any, Other::Arguments)".
>
> How?  Not gonna show you.  Too much ugly code out there already.
>
> -Dave
>
> --
> Dave Aronson, FREELANCE SOFTWARE DEVELOPER LOOKING FOR REMOTE CONTRACTS
> (or temp jobs, or in/near Fairfax VA; see www.Codosaur.us for details);
> see also www.PullRequestRoulette.com, Blog.Codosaur.us, www.Dare2XL.com

I'm more curious what you intend to do with this. There may be a more
ruby way of doing what you want rather than just making something work
the way it does in another language. What is the use case for this
sort of thing? When you have the ability to do what you want, what
does that get you?

I've found and been shown ever more some awesome ways of doing things
in ruby that my previous experience had me going in a different
direction.