Skip to content

Instantly share code, notes, and snippets.

@leejarvis

leejarvis/1.rb Secret

Created March 31, 2015 15:29
Show Gist options
  • Save leejarvis/04437cbff195ec495886 to your computer and use it in GitHub Desktop.
Save leejarvis/04437cbff195ec495886 to your computer and use it in GitHub Desktop.
module Truncate
refine String do
def truncate(n: 100)
self[0...n]
end
end
end
class Foo
using Truncate
def foo
something.truncate
end
def bar
something.truncate
end
def baz
something.truncate
end
end
class Foo
def foo
truncate something
end
def bar
truncate something
end
def baz
truncate something
end
private
def truncate(v, n: 100)
v[0...n]
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment