Nothing ventured, nothing gained

a blog by Marc Chung

How to use Method#to_ruby

»

by Marc Chung

From the ruby part of the brain.

In Ruby, there’s a handy dandy way to get a string representation of a method.

hoktauri$ cat method_to_ruby.rb
def bacon
  "chunky"
end

if $0 == __FILE__
  require 'rubygems'
  require 'ruby2ruby'
  require 'parse_tree_extensions'
  require 'pp'
  pp method(:bacon).to_ruby
end

hoktauri$ ruby method_to_ruby.rb
"def bacon\n \"chunky\"\nend"

Uses the ruby2ruby and ParseTree gems.

Want to know more?

I'm Marc Chung, and you're reading Nothing ventured, Nothing gained, a blog about building beautiful software. I'm the founder of OpenRain Software, a web design and development company located in Arizona, where I make millions of users happy by building breathtaking software with brilliant people.

Presentations, Talks, Etc