[Ruby]トップレベルで定義されたメソッドはObjectに属するのでどこからでも呼べる。
#!/usr/local/bin/ruby p self.class def hello(target) puts "hello #{target}" end class Person hello("ryouichi") def hello2 hello("yurichan") end end hello("t9md") Person.new.hello2
- 実行結果
Object
hello ryouichi
hello t9md
hello yurichan