0

I'm absolutely new to Ruby and I'm using my Mac terminal.
I'm following this getting-started tutorial but after I created a Greeter object:

g = Greeter.new("Pat")

Nothing happens, no error messages whatsoever.
I though I'm supposed to see something like:

=> #<Greeter:0x16cac @name="Pat">

What's wrong, am I supposed to install something extra for Ruby to work properly on my Mac?

4

1 回答 1

1

Try this: :)

class Greeter
 def initialize(x)
  @name = x
 end
end
p g = Greeter.new("Pat") #=> #<Greeter:0x105c840 @name="Pat">

Or if you started this way:

C:\>irb --simple-prompt --noecho
>> class Greeter
>>  def initialize(x)
>>   @name = x
>>  end
>> end
>> g = Greeter.new("Pat")
>> p g
#<Greeter:0x11e8300 @name="Pat">

Nothing would come as --noecho option disable the IRB inspection as =>.

于 2013-04-12T09:41:11.523 回答