Skip to content

Instantly share code, notes, and snippets.

@zzak
Created February 16, 2011 19:49

Revisions

  1. zzak created this gist Feb 16, 2011.
    6 changes: 6 additions & 0 deletions gistfile1.rb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,6 @@
    def add_method(obj, mod, &blk)
    obj.class_eval { define_method(mod, &blk) }
    end
    add_method(String, :greet) { "Hello, #{self}" }

    "world".greet #=> "Hello, world!"