locate a line of code
Sometimes you want to know in which file and line a method is defined.
This snippet should do that job.
Labels: reflection, ruby
Sometimes you want to know in which file and line a method is defined.
Labels: reflection, ruby
Example:
template = 'Hello #{name}!'
name = 'Paul'
puts eval(%{"#{template}"}) # => Hello Paul!
name = 'Holger'
puts eval(%{"#{template}"}) # => Hello Holger!Note that the template definition use a single qutoed string, so no variables are evaluated within the template string.
Labels: programmieren, ruby