Class: ParanoidDummy::Dummy

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeDummy

Returns a new instance of Dummy.



6
7
8
# File 'lib/paranoid_dummy/dummy.rb', line 6

def initialize
  @default = ''
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

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



24
25
26
27
# File 'lib/paranoid_dummy/dummy.rb', line 24

def method_missing method, *args, &block
  return default unless self.respond_to? method
  super
end

Instance Attribute Details

#defaultObject (readonly)

Returns the value of attribute default.



4
5
6
# File 'lib/paranoid_dummy/dummy.rb', line 4

def default
  @default
end

Instance Method Details

#defaults_to(value) ⇒ Object



20
21
22
# File 'lib/paranoid_dummy/dummy.rb', line 20

def defaults_to value
  @default = value
end

#metaclassObject



29
30
31
# File 'lib/paranoid_dummy/dummy.rb', line 29

def metaclass
  class << self; self; end
end

#responds_to(method, options = {}) ⇒ Object



10
11
12
13
14
15
16
17
18
# File 'lib/paranoid_dummy/dummy.rb', line 10

def responds_to method, options = {}
  if options[:with].present?
    instance_variable_set "@#{method}".to_sym, options[:with]

    metaclass.send :redefine_method, method.to_sym do |*args|
      instance_variable_get "@#{method}".to_sym
    end
  end
end