The end result of a confusing sentence with no
>
> context is that I have no idea what you are trying to say. Could you try
>
> explaining again please?
>
>
> Steven
No problem my reply from phone at work a little confusing.
So trying to determine what this does.
def ins_var
@ins_var ||= nil
end
In particular I was guessing at this.
@ins_var ||= nil
Which I have now found on Rubyinside
http://www.rubyinside.com/21-ruby-tricks-902.html
>From there
7 - Cut down on local variable definitions
Instead of defining a local variable with some initial content (often just an
empty hash or array), you can instead define it "on the go" so you can perform
operations on it at the same time:
(z ||= []) << 'test'
2009 Update: This is pretty rancid, to be honest. I've changed my mind; you
shouldn't be doing this :)
So now that I know this I am still further lost to the point of the initially
posted code so my kubuntu has ruby so I have run it, and honestly I need
further definition on what that code was trying to acheive.
sayth@sayth-TravelMate-5740G:~/scripts$ ruby --version
ruby 1.9.3p484 (2013-11-22 revision 43786) [x86_64-linux]
sayth@sayth-TravelMate-5740G:~/scripts$ irb
irb(main):001:0> (z ||= []) << 'test'
=> ["test"]
irb(main):002:0> @ins_var ||= nil
=> nil
irb(main):003:0> def ins_var
irb(main):004:1> @ins_var ||= nil
irb(main):005:1> end
=> nil
irb(main):006:0> def m
irb(main):007:1> @ins_var = "val"
irb(main):008:1> end
=> nil
irb(main):009:0> def m2
irb(main):010:1> ins_var #=> "val"
irb(main):011:1> end
=> nil
irb(main):012:0> m
=> "val"
irb(main):013:0> m2
=> "val"
Sayth
--
https://mail.python.org/mailman/listinfo/python-list