Skip to content

Instantly share code, notes, and snippets.

@osyo-manga
Created July 8, 2015 11:50
Show Gist options
  • Select an option

  • Save osyo-manga/d758893d64bc20025833 to your computer and use it in GitHub Desktop.

Select an option

Save osyo-manga/d758893d64bc20025833 to your computer and use it in GitHub Desktop.
custom puts
module Output
def puts output
if output.class == Person
super output.to_o
else
super output
end
end
end
module Kernel
prepend Output
end
include Kernel
class Person
def initialize name, age
@name, @age = name, age
end
def to_o
"name : #{@name}, age : #{@age}"
end
# def to_s
# "name : #{@name}, age : #{@age}"
# end
end
homu = Person.new "homu", 14
puts homu
# => name : homu, age : 14
puts "mami"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment