Skip to content

Instantly share code, notes, and snippets.

@externvoid
Created March 8, 2018 14:17
Show Gist options
  • Select an option

  • Save externvoid/f8c7420547449c5afa412d1e988bffaa to your computer and use it in GitHub Desktop.

Select an option

Save externvoid/f8c7420547449c5afa412d1e988bffaa to your computer and use it in GitHub Desktop.
クラスメソッド、得意メソッドの作り方
# 得意メソッド、クラスメソッド定義2連発、3連発
# class << C, class << a, def self.foo, def a.foo
class C;end
# (1)
class << C
def foo
puts 'OK'
end
end
class C
foo
end
class C
# (2)
def self.bar
puts 'OK bar'
end
end
C.bar
class C
# (3)
class << self
def baz
puts 'OK baz'
end
end
end
C.baz
# -------
a = "OK"
# [1]
def a.foo
puts 'OK foo'
end
a.foo
class << a
# [2]
def bar
puts 'Or bar'
end
end
a.bar
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment