ruby - attr_reader only working in some environments -


this applies attr_writer , attr_accessor.

i've been playing simple ruby code , following snippet not work in environments i've run it:

class human   attr_reader :name   def initialize(name)     @name = name   end end  hank = human.new("hank") hank.name 

this should output "hank", in command line irb. in textmate2 , aptana studio 3, nothing outputs when run code. 3 work expected if explicitly define reader:

def name   puts @name end 

when play in aptana terminal , usual terminal , type:

$ ruby -v 

they both appear use same version: ruby 2.0.0p451. what's going on?

attr_reader doesn't think does.

try

puts hank.name 

rather than

hank.name 

and you'll see output. irb special case, shows return value of last statement executed. ruby on own won't that, prints things explicitly tell print.


Comments

Popular posts from this blog

javascript - RequestAnimationFrame not working when exiting fullscreen switching space on Safari -

jsf - How to ajax update an item in the footer of a PrimeFaces dataTable? -

jquery - Keeping Kendo Datepicker in min/max range -