Class: TwentyFortyEight::Dsl

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

Overview

Dsl

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(settings = {}, &block) ⇒ Dsl

Returns a new instance of Dsl.



7
8
9
10
# File 'lib/TwentyFortyEight/dsl.rb', line 7

def initialize(settings = {}, &block)
  @callable = block
  @settings = settings
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(sym, *args, &block) ⇒ Object



19
20
21
# File 'lib/TwentyFortyEight/dsl.rb', line 19

def method_missing(sym, *args, &block)
  return sym if game.action(sym, insert: false).changed?
end

Instance Attribute Details

#gameObject (readonly)

Returns the value of attribute game.



5
6
7
# File 'lib/TwentyFortyEight/dsl.rb', line 5

def game
  @game
end

#settingsObject (readonly)

Returns the value of attribute settings.



5
6
7
# File 'lib/TwentyFortyEight/dsl.rb', line 5

def settings
  @settings
end

Instance Method Details

#apply(game) ⇒ Object



12
13
14
15
16
17
# File 'lib/TwentyFortyEight/dsl.rb', line 12

def apply(game)
  @queue = []
  @game  = game.dup

  instance_eval(&@callable)
end

#respond_to_missing?(sym, *args, &block) ⇒ Boolean

Returns:

  • (Boolean)


23
24
25
# File 'lib/TwentyFortyEight/dsl.rb', line 23

def respond_to_missing?(sym, *args, &block)
  true
end