Re: ruby instance variable in python
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
Re: ruby instance variable in python
On Monday, 6 October 2014 21:07:24 UTC+11, roro codeath wrote: in ruby: module M def ins_var @ins_var ||= nil end def m @ins_var = 'val' end def m2 m ins_var # = 'val' end end in py: # m.py # how to def ins_var def m: # how to set ins_var def m2: m() # how to get ins var I took || to be a ternary. So I assumed your code just sets ins_var to nil and then is called in module m and supplied a val. Could be wrong. if ins_var is None: ins_var = 'val' -- https://mail.python.org/mailman/listinfo/python-list
Re: ruby instance variable in python
flebber writes: On Monday, 6 October 2014 21:07:24 UTC+11, roro codeath wrote: in ruby: module M def ins_var @ins_var ||= nil end ... I took || to be a ternary. So I assumed your code just sets ins_var to nil and then is called in module m and supplied a val. Could be wrong. if ins_var is None: ins_var = 'val' Just out of interest, please, do you think the word 'ternary' is more or less synonymous with 'conditional'? I'm not being sarcastic. This possibility just occurred to me, and the world will begin to make more sense to me if it turns out that there are people who simply do not think 'three' when they think 'ternary'. -- https://mail.python.org/mailman/listinfo/python-list
Re: ruby instance variable in python
I thought that it was a shortcut in ruby to negate the other option of providing another default . I don't greatly know ruby but took a guess after reading examples here https://blog.neowork.com/ruby-shortcuts -- https://mail.python.org/mailman/listinfo/python-list
Re: ruby instance variable in python
flebber wrote: I thought that it was a shortcut in ruby to negate the other option of providing another default . I'm afraid I can't work out what that sentence means, to negate the other option of providing *another* default? How many defaults are you providing? Then you negate *the option*, does that mean that you're not actually providing a default? Also, since you haven't quoted the person you are responding to, there is no context to your response. 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 -- https://mail.python.org/mailman/listinfo/python-list
Re: ruby instance variable in python
Hello, If you explain what the ruby code does, I think much more people will be able to help you. Don't forget, this is a Python list. Not everybody knows Ruby here. Best 2014-10-06 12:06 GMT+02:00 roro codeath rorocode...@gmail.com: in ruby: module M def ins_var @ins_var ||= nil end def m @ins_var = 'val' end def m2 m ins_var # = 'val' end end in py: # m.py # how to def ins_var def m: # how to set ins_var def m2: m() # how to get ins var -- https://mail.python.org/mailman/listinfo/python-list -- https://mail.python.org/mailman/listinfo/python-list
Re: ruby instance variable in python
On 06/10/2014 11:45, David Palao wrote: Hello, If you explain what the ruby code does, I think much more people will be able to help you. Don't forget, this is a Python list. Not everybody knows Ruby here. Best 2014-10-06 12:06 GMT+02:00 roro codeath rorocode...@gmail.com: in ruby: Please don't top post here, thank you. -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence -- https://mail.python.org/mailman/listinfo/python-list
Re: ruby instance variable in python
roro codeath wrote: in ruby: module M def ins_var @ins_var ||= nil end def m @ins_var = 'val' end def m2 m ins_var # = 'val' end end I admit that my Ruby skills are admittedly pretty lousy. Still, I used to think that Ruby was pretty readable, but I find the above completely meaningless. So I'm going to guess what you want, sorry if I guess wrong. in py: # m.py # how to def ins_var def m: # how to set ins_var def m2: m() # how to get ins var Please explain what you mean by instance variable. There are two standard things which it could be. (1) A string variable is a variable holding a string. A float variable is a variable holding a float. A list variable is a variable holding a list. So an instance variable must be a variable holding an instance. ins_var = NameOfTheClass(arg) You just instantiate the class, passing whatever arguments it expects. (2) In the Java world, instance variable doesn't mean a variable at all, but an attribute of classes which is stored on the instance. (As opposed to those attributes stored on the class itself, which they refer to as static, since in Java they are known to the compiler.) To define instance variables (attributes), you have to have a class to define them in. Remember that Python uses the Offside Rule (significant indentation). class MyClass(object): # subclass of object def __init__(self, arg): # Initialise the instance. self.ins_var = arg def method(self, arg): return self.ins_var == arg: instance = MyClass(some value) print(instance.ins_var) # prints some value instance.method(spam and eggs) # returns False instance.method(some value) # returns True Does this help? -- Steven -- https://mail.python.org/mailman/listinfo/python-list