mirror of
https://github.com/mruby/mruby
synced 2026-06-08 16:11:16 +00:00
927615e1f0
- Added to `mruby-binding-core` - `Binding#local_variable_defined?` - `Binding#local_variable_get` - `Binding#local_variable_set` - `Binding#local_variables` - `Binding#receiver` - `Binding#source_location` - `Binding#inspect` - Added to `mruby-proc-binding` - `Proc#binding` The reason for separating `Proc#binding` is that core-mrbgems has a method that returns a closure object to minimize possible problems with being able to manipulate internal variables. By separating it as different mrbgem, each user can judge this problem and incorporate it arbitrarily.
23 lines
662 B
Ruby
23 lines
662 B
Ruby
assert "Proc#binding" do
|
|
block = ->(i) {}
|
|
a, b, c = 1, 2, 3
|
|
bind = block.binding
|
|
assert_equal([:a, :b, :bind, :block, :c], bind.local_variables.sort)
|
|
assert_equal(1, bind.local_variable_get(:a))
|
|
assert_equal(5, bind.eval("b + c"))
|
|
bind.local_variable_set(:x, 9)
|
|
assert_equal(9, bind.local_variable_get(:x))
|
|
end
|
|
|
|
assert("Binding#source_location after Proc#binding") do
|
|
skip unless -> {}.source_location
|
|
|
|
block, source_location = -> {}, [__FILE__, __LINE__]
|
|
assert_equal source_location, block.binding.source_location
|
|
end
|
|
|
|
assert "Proc#binding and .eval from C" do
|
|
bind = proc_in_c.binding
|
|
assert_nothing_raised { bind.eval("self") }
|
|
end
|