Class: Detroit::Toolchain::Script::CustomContext

Inherits:
Object
  • Object
show all
Defined in:
lib/detroit/toolchain/script.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(&b) ⇒ CustomContext

Returns a new instance of CustomContext.



199
200
201
202
# File 'lib/detroit/toolchain/script.rb', line 199

def initialize(&b)
  @settings = {}
  b.arity == 0 ? instance_eval(&b) : b.call(self)
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(s, a = nil, *x, &b) ⇒ Object



204
205
206
207
208
209
210
211
212
# File 'lib/detroit/toolchain/script.rb', line 204

def method_missing(s,a=nil,*x,&b)
  case s.to_s
  when /=$/
    @settings[s.to_s.chomp('=').to_sym] = b ? b : a
  else
    return @settings[s] unless a
    @settings[s] = b ? b : a
  end
end

Instance Attribute Details

#settingsObject (readonly)

Returns the value of attribute settings.



197
198
199
# File 'lib/detroit/toolchain/script.rb', line 197

def settings
  @settings
end

Instance Method Details

#respond_to?(s) ⇒ Boolean

Returns:

  • (Boolean)


213
214
215
# File 'lib/detroit/toolchain/script.rb', line 213

def respond_to?(s)
  @settings.key?(s.to_sym)
end