Class: DialogTui::Option

Inherits:
Object
  • Object
show all
Defined in:
lib/dialog_tui.rb

Overview

NOTE: not sure about perfomance implications of that chain of &block passing instead of just using variable w/o ‘&` but & looks very explicit and is not as annoying as additional parameter

Instance Method Summary collapse

Constructor Details

#initialize(dialog, text, &reaction) ⇒ Option

Returns a new instance of Option.



117
118
119
120
121
# File 'lib/dialog_tui.rb', line 117

def initialize dialog, text, &reaction
  @dialog = dialog
  @text = text.to_s
  @reaction = reaction
end

Instance Method Details

#callObject



123
124
125
# File 'lib/dialog_tui.rb', line 123

def call
  @reaction.call
end

#chosen?Boolean

Returns:

  • (Boolean)


136
137
138
# File 'lib/dialog_tui.rb', line 136

def chosen?
  @dialog.chosen? self
end

just to be here for future



127
128
129
130
131
132
133
134
# File 'lib/dialog_tui.rb', line 127

def print printer=nil  # just to be here for future
                                      # refactoring
  if chosen?
    puts '=> ' + @text
  else
    puts '   ' + @text
  end
end