diff options
| author | dearblue <[email protected]> | 2020-05-21 21:27:51 +0900 |
|---|---|---|
| committer | Yukihiro "Matz" Matsumoto <[email protected]> | 2020-06-02 14:49:27 +0900 |
| commit | f85906b67920c0e69599c6e59d843274aef152be (patch) | |
| tree | 1f6852e91266cd14899974d725dffbeedfb9cd37 /mrbgems/mruby-eval/test | |
| parent | 1fc9345b4567bf65ed27d1ed7a84002b898f08d2 (diff) | |
| download | mruby-f85906b67920c0e69599c6e59d843274aef152be.tar.gz mruby-f85906b67920c0e69599c6e59d843274aef152be.zip | |
Remove `patch_irep()` in `mruby-eval`
- It can now deal with operands in the range of `OP_EXT*`.
- It can now call the same method as the variable name without arguments.
```ruby
def a
"Safe!"
end
a = "Auto!"
eval "a()" # call method `a`
```
Diffstat (limited to 'mrbgems/mruby-eval/test')
| -rw-r--r-- | mrbgems/mruby-eval/test/eval.rb | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/mrbgems/mruby-eval/test/eval.rb b/mrbgems/mruby-eval/test/eval.rb index 4930259c1..639ed68f9 100644 --- a/mrbgems/mruby-eval/test/eval.rb +++ b/mrbgems/mruby-eval/test/eval.rb @@ -130,3 +130,24 @@ Proc.new { foo } EOS } end + +assert('Calling the same method as the variable name') do + hoge = Object.new + def hoge.fuga + "Hit!" + end + assert_equal("Hit!") { fuga = "Miss!"; eval "hoge.fuga" } + assert_equal("Hit!") { fuga = "Miss!"; -> { eval "hoge.fuga" }.call } + assert_equal("Hit!") { -> { fuga = "Miss!"; eval "hoge.fuga" }.call } + assert_equal("Hit!") { fuga = "Miss!"; eval("-> { hoge.fuga }").call } +end + +assert('Access numbered parameter from eval') do + hoge = Object.new + def hoge.fuga(a, &b) + b.call(a) + end + assert_equal(6) { + hoge.fuga(3) { _1 + eval("_1") } + } +end |
