Reputation: 678
I was trying to see if I could transfer an instance variable's attributes using a simple do
statement.
class Dog
def initialize(name, age)
@name = name
@age = age
end
def bark
puts 'Woof'
puts 'Woof'
puts 'Woof'
end
end
bo = Dog.new do |word|
word.bark
end
Why does it return the class id instead of the function's output?
Upvotes: 0
Views: 72
Reputation: 2791
As it is suggested in comments, passing block to new
statement makes no sense.
You can change your code to:
bo = Dog.new('Rusty', 3).tap do |word|
word.bark
end
and it will bark as expected. :)
Upvotes: 5