Ralph Shnelvar wrote:
> I very often do something like:
>   puts "some_variable.something = #{some_variable.something}"
> 
> That repetition is getting annoying.
> 
> Is there an idiomatic Ruby way to do something like
>   puts_v some_variable.something

Given this:

  some_variable = Object.new
  def some_variable.something; "hello"; end

# Option 1

  def puts_v(str, b)
    puts "#{str} = #{eval(str, b).inspect}"
  end

  puts_v "some_variable.something", binding

# Option 2, using a block to get the Binding

  def puts_v(&blk)
    str = yield
    puts "#{str} = #{eval(str, blk).inspect}"
  end

  puts_v { "some_variable.something" }

# Option 2a, looks a bit odd

  puts_v {%{some_variable.something}}

# Google also for Binding.of_caller
-- 
Posted via http://www.ruby-forum.com/.