0

Hello I'm trying to learn ruby blocks. But I have a trouble to get over this construction:

class SomeApp

  attr_accessor :load_listener

  def on_load(&block)
    @load_listener = block
  end

  def load(x)
    @load_listener.call(x) if @load_listener
  end

end

app = SomeApp.new
app.on_load { |x| puts 'on load #{x}'} 
app.load(5)

I don't understand why result of this code is 'on load #{x}', instead of 'on load 5' Any help is appreciated.

1 Answer 1

5

You're using single quotes (') instead of double quotes ("). String interpolation (#{...}) does only work with double quotes.

Change puts 'on load #{x}' to puts "on load #{x}".

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.