Skip to content

Instantly share code, notes, and snippets.

@nusco
Created March 4, 2014 16:51
Show Gist options
  • Select an option

  • Save nusco/9350331 to your computer and use it in GitHub Desktop.

Select an option

Save nusco/9350331 to your computer and use it in GitHub Desktop.

Revisions

  1. nusco revised this gist Mar 4, 2014. 1 changed file with 0 additions and 1 deletion.
    1 change: 0 additions & 1 deletion refinement.rb
    Original file line number Diff line number Diff line change
    @@ -13,7 +13,6 @@ def reverse
    end

    "abc".reverse # => "cba"

    using MyRefinement
    "abc".reverse # => "my reverse"

  2. nusco created this gist Mar 4, 2014.
    20 changes: 20 additions & 0 deletions refinement.rb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,20 @@
    # =================
    # Spell: Refinement
    # =================

    # Patch a class until the end of the file, or (from Ruby 2.1) until the end of the including module.

    module MyRefinement
    refine String do
    def reverse
    "my reverse"
    end
    end
    end

    "abc".reverse # => "cba"

    using MyRefinement
    "abc".reverse # => "my reverse"

    # For more information: http://www.pragprog.com/titles/ppmetr/metaprogramming-ruby