Skip to content

Instantly share code, notes, and snippets.

@jphager2
Last active December 2, 2016 12:19
Show Gist options
  • Save jphager2/e986131f13ce794f444e2ad0dc0e7906 to your computer and use it in GitHub Desktop.
Save jphager2/e986131f13ce794f444e2ad0dc0e7906 to your computer and use it in GitHub Desktop.
class MyString < SimpleDelegator
def cut!(start_pos, end_pos)
new_string = begin
# your magic
end
__getobj__.replace(new_string)
end
end
my_string = MyString.new('whatever whatever')
my_string.cut!('what', 'what')
# or if you only needed a few methods
class MyString
extend Forwardable
attr_reader :string
def_delegators :string, :to_s, :sub, :gsub # Whatever methods you need
def initialize(string)
@string = string
end
def cut!(start_pos, end_pos)
new_string = begin
# your magic
end
string.replace(new_string)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment