Giter Site home page Giter Site logo

Comments (3)

abinoam avatar abinoam commented on July 20, 2024 1

Thank you for reporting such a problematic issue!

I have had a quick look at the issue.
Debugging I can see that after getting the menus set, all procs have different ids.

(byebug) all_items
[#<HighLine::Menu::Item:0x007fcdc3938008 @name="Option 1", @text="Option 1", @help=nil, @action=#<Proc:0x007fcdc39681e0@issue_207.rb:12>>, #<HighLine::Menu::Item:0x007fcdc302e9f8 @name="Option 2", @text="Option 2", @help=nil, @action=#<Proc:0x007fcdc3109170@issue_207.rb:12>>]
@action=#<Proc:0x007fcdc39681e0@issue_207.rb:12>>
@action=#<Proc:0x007fcdc3109170@issue_207.rb:12>>

But if I eval option inside of each proc I get the same object, then option.message will give the same result.

# For 1 and 0 indexed menus (after 2 menus set).
# All two eval to the same object, the last one (Message 2)

(byebug) all_items[1].action.binding.eval("option")
#<struct Test::Option title="Option 2", message="Message 2">
(byebug) all_items[0].action.binding.eval("option")
#<struct Test::Option title="Option 2", message="Message 2">

I'll take more time on it at the weekend! Any news, please contact us! 👍

from highline.

abinoam avatar abinoam commented on July 20, 2024 1

Well... I think it's solved!

Use each instead. Forget for.

The reason why: http://stackoverflow.com/questions/5677081/ruby-what-is-the-difference-between-a-for-loop-and-an-each-loop

require 'highline'

class Test
  Option = Struct.new(:title, :message)

  def initialize

    cli = HighLine.new

    cli.choose do |menu|
      options.each do |option|
        menu.choice(option.title) { puts option.message }
      end
    end

  end

  def options
    [Option.new('Option 1', 'Message 1'), Option.new('Option 2', 'Message 2'), Option.new('Option 3', 'Message 3')]
  end
end

Test.new

Dear @rafaelsachetto, can I close this issue as resolved? Any doubt? Feel free to ask! And, thank you again.

from highline.

rafaelsachetto avatar rafaelsachetto commented on July 20, 2024 1

Dear @abinoam you're rock, thanks alot for your amazing explanation, attention and support.

from highline.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.