Skip to content

Useful ruby functions

golive edited this page Aug 29, 2012 · 1 revision

Contextualize to an object

def with(object, &block)
  object.instance_eval(&block)
end

Example:

a = '1234'

with a do
  with to_i do
    puts self + 1
  end
end
Clone this wiki locally