Class: Main::Mode::List
Instance Method Summary collapse
- #add(klass) ⇒ Object
- #find_by_mode(m, options = {}) ⇒ Object
-
#initialize(*a, &b) ⇒ List
constructor
A new instance of List.
Constructor Details
#initialize(*a, &b) ⇒ List
Returns a new instance of List.
10 11 12 13 14 |
# File 'lib/main/mode.rb', line 10 def initialize *a, &b super ensure self.fields = [] end |
Instance Method Details
#add(klass) ⇒ Object
16 17 18 19 20 |
# File 'lib/main/mode.rb', line 16 def add klass mode_name = Mode.new klass.mode_name raise Duplicate, mode_name if has_key? mode_name self[mode_name] = klass end |
#find_by_mode(m, options = {}) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/main/mode.rb', line 22 def find_by_mode m, = {} each_pair do |mode, klass| return mode if mode == m end candidates = [] each_pair do |mode, klass| candidates << mode if mode.index(m) == 0 end case candidates.size when 0 nil when 1 candidates.first else raise Ambiguous, "ambiguous mode: #{ m } = (#{ candidates.sort.join ' or ' })?" end end |