Does ruby expression expansion via #{} do double expansion? -


okay, per suggestions on clarifying intent have restated question. hope example clear.

$funcname = "" $message = "" $debugformat = "within #{$funcname} message: #{$message}"   def    $funcname = "something"    # .    # .    # .    $message = "an important message."    puts "#{$debugformat}"  end  def    $funcname = "another"    # method related code ...    $message = "result message output"    puts "#{$debugformat}" end 

so, idea have various debug related strings use in various places without needing repeat same formatting , such.

anyway, isn't super critical it's more attempt try , learn ruby better.

go easy,

-daniel

no, not possible have shown. #{} syntax string interpolation, when write pp = "[#{fname}]", it's storing string [empty] in variable pp. strings have no memory of code used produce them.

it's unclear you're attempting achieve this, more method more appropriate string interpolation.


update since edit: seems want create sort of simulated stack trace. string interpolation still doesn't make sense. instead, this:

def debug(message)   puts "#{ caller[0][/`([^']*)'/, 1]}: #{message}" end  def   debug "an important message" end  def   debug "result message output" end  

based on strange usage of global variables , constants, seems you're trying apply ideas other language in ways don't fit ruby. i'd recommend looking through ruby book familiar basics.


Comments

Popular posts from this blog

jQuery clickable div with working mailto link inside -

java - Getting corefrences with Standard corenlp package -

WPF: binding viewmodel property of type DateTime to Calendar inside ItemsControl -