Created
July 8, 2015 11:50
-
-
Save osyo-manga/d758893d64bc20025833 to your computer and use it in GitHub Desktop.
custom puts
This file contains hidden or 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
| 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