Skip to content

Instantly share code, notes, and snippets.

@ftiasch
Created October 14, 2020 06:36
Show Gist options
  • Save ftiasch/6da1ef60acc17765b0aec3a7a552618b to your computer and use it in GitHub Desktop.
Save ftiasch/6da1ef60acc17765b0aec3a7a552618b to your computer and use it in GitHub Desktop.
demonstrate the danger extending Ruby code objects with custom data members
class MyString < String
attr_reader :flag
def initialize(s, f)
super s
@flag = f
end
end
s1 = MyString.new ' misa', :misa
s2 = s1.lstrip
p [s1.flag, s2.flag]
s1.lstrip!
p s1.flag
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment