You can accomplish this by explicitly passing in the current binding:
def func(x, bdg)
eval "#{x} += 1", bdg
end
a = 5
func(:a, binding)
puts a # => 6
More Related Contents:
- What does map(&:name) mean in Ruby?
- `&:views_count` in `Post.published.collect(&:views_count)` [duplicate]
- Ruby syntax error, unexpected tIDENTIFIER, expecting end-of-input
- Ruby metaclass confusion
- What are all the common ways to read a file in Ruby?
- Ruby: kind_of? vs. instance_of? vs. is_a?
- What are the Ruby File.open modes and options?
- What does a double * (splat) operator do
- How to get a single character without pressing enter?
- Hidden features of Ruby
- Checking if a variable is defined?
- Instance variable: self vs @
- naked asterisk as parameter in method definition: def f(*)
- When should I use Struct vs. OpenStruct?
- Spawn a background process in Ruby
- Ruby: Destructors?
- How to match all occurrences of a regular expression in Ruby
- gem eventmachine fatal error: ‘openssl/ssl.h’ file not found
- Running a command from Ruby displaying and capturing the output
- In Rails, how to add a new method to String class?
- Why isn’t self always needed in ruby / rails / activerecord?
- Chrome 62 and Flash
- What is the difference between Raising Exceptions vs Throwing Exceptions in Ruby?
- List of installed gems?
- How can I find the number of days between two Date objects in Ruby?
- What are those pipe symbols for in Ruby?
- Ruby’s yield feature in relation to computer science
- How to convert JSON to a Ruby hash
- Why isn’t current directory on my Ruby path? [duplicate]
- Iterate over Ruby Time object with delta