Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #78835
| Newsgroups | comp.lang.python |
|---|---|
| Date | 2014-10-08 03:12 -0700 |
| References | <mailman.14632.1412590002.18130.python-list@python.org> <b22416b5-e3ed-4ece-aeba-65603fff1b3f@googlegroups.com> <qotzjd8nj3d.fsf@ruuvi.it.helsinki.fi> <48972e63-c980-4025-a624-cda0b60367de@googlegroups.com> <54349433$0$13001$c3e8da3$5496439d@news.astraweb.com> |
| Message-ID | <54c71633-8657-460e-9bf3-d20350e77a2e@googlegroups.com> (permalink) |
| Subject | Re: ruby instance variable in python |
| From | flebber <flebber.crue@gmail.com> |
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
Back to comp.lang.python | Previous | Next — Previous in thread | Find similar | Unroll thread
ruby instance variable in python roro codeath <rorocodeath@gmail.com> - 2014-10-06 18:06 +0800
Re: ruby instance variable in python Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2014-10-07 05:54 +1100
Re: ruby instance variable in python flebber <flebber.crue@gmail.com> - 2014-10-07 05:29 -0700
Re: ruby instance variable in python Jussi Piitulainen <jpiitula@ling.helsinki.fi> - 2014-10-07 15:46 +0300
Re: ruby instance variable in python flebber <flebber.crue@gmail.com> - 2014-10-07 17:59 -0700
Re: ruby instance variable in python Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2014-10-08 12:32 +1100
Re: ruby instance variable in python flebber <flebber.crue@gmail.com> - 2014-10-08 03:12 -0700
csiph-web