# class << self opens up self's singleton class, so that methods can be redefined for the current self object
class String
class << self
def value_of obj
obj.to_s
end
end
end
String.value_of 42 # => "42"
# This can also be written as a shorthand:
class String
def self.value_of obj
obj.to_s
end
end
# Even shorter
def String.value_of obj
obj.to_s
end