amirrajan / rubymotion-applied

RubyMotion documentation provided by the community. Submit a pull request to the docs for a free one year indie subscription.
Apache License 2.0
49 stars 10 forks source link

Scope issue with blocks #100

Open johanparin opened 6 years ago

johanparin commented 6 years ago

I'm seeing an issue where the parameter to the block overwrites a local variable with the same name. I don't know if this is simply a Ruby version issue or if it is a rubymotion bug. Anyways, I wanted to share and get your opinion. Here is an example:

  def scope_test
    x = 10
    y = [1, 2, 3]
    z = y.map { |x| x + 1 }
    puts "x is now: #{x}"
    [x, z]
  end

I would expect this to output 10, which is indeed what I get using Ruby 2.4.4. In rubymotion I get 3.

Comments on this?

/Johan

amirrajan commented 6 years ago

Confirmed 👍

Thanks for the report.

hboon commented 6 years ago

FWIW, I think this has been around forever in RM.

amirrajan commented 6 years ago

It's low priority yes. But at least it's on the books.

hboon commented 6 years ago

I don't mind. Encourages shorter methods :)