diff options
| author | Yukihiro "Matz" Matsumoto <[email protected]> | 2017-12-18 11:59:36 +0900 |
|---|---|---|
| committer | GitHub <[email protected]> | 2017-12-18 11:59:36 +0900 |
| commit | d9049c10fa922e6978257eaf9fa777b4f844777d (patch) | |
| tree | 935f0dde3bdccc15a0f3325c54f84ca29dc55f86 /mrbgems/mruby-method/mrblib | |
| parent | bba6c9a1cefe92d5d4f11d09cfc0c48d6b207b5f (diff) | |
| parent | c0914dbb65afb5cf428bdbf3d73c8855e0b34518 (diff) | |
| download | mruby-d9049c10fa922e6978257eaf9fa777b4f844777d.tar.gz mruby-d9049c10fa922e6978257eaf9fa777b4f844777d.zip | |
Merge pull request #3904 from ksss/mruby-method
Add mruby-method
Diffstat (limited to 'mrbgems/mruby-method/mrblib')
| -rw-r--r-- | mrbgems/mruby-method/mrblib/kernel.rb | 9 | ||||
| -rw-r--r-- | mrbgems/mruby-method/mrblib/method.rb | 20 | ||||
| -rw-r--r-- | mrbgems/mruby-method/mrblib/unbound_method.rb | 9 |
3 files changed, 38 insertions, 0 deletions
diff --git a/mrbgems/mruby-method/mrblib/kernel.rb b/mrbgems/mruby-method/mrblib/kernel.rb new file mode 100644 index 000000000..b2ebd45ea --- /dev/null +++ b/mrbgems/mruby-method/mrblib/kernel.rb @@ -0,0 +1,9 @@ +module Kernel + def singleton_method(name) + m = method(name) + if m.owner != singleton_class + raise NameError, "undefined method `#{name}' for class `#{singleton_class}'" + end + m + end +end diff --git a/mrbgems/mruby-method/mrblib/method.rb b/mrbgems/mruby-method/mrblib/method.rb new file mode 100644 index 000000000..5de0afdf7 --- /dev/null +++ b/mrbgems/mruby-method/mrblib/method.rb @@ -0,0 +1,20 @@ +class Method + def to_proc + m = self + lambda { |*args, &b| + m.call(*args, &b) + } + end + + def owner + @owner + end + + def receiver + @recv + end + + def name + @name + end +end diff --git a/mrbgems/mruby-method/mrblib/unbound_method.rb b/mrbgems/mruby-method/mrblib/unbound_method.rb new file mode 100644 index 000000000..1d3acf3fa --- /dev/null +++ b/mrbgems/mruby-method/mrblib/unbound_method.rb @@ -0,0 +1,9 @@ +class UnboundMethod + def owner + @owner + end + + def name + @name + end +end |
