Last active
December 2, 2016 12:19
-
-
Save jphager2/e986131f13ce794f444e2ad0dc0e7906 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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