Class: NackClass

Inherits:
Object show all
Defined in:
lib/mega/nack.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(error = nil, *data, &ctrl) ⇒ NackClass

Returns a new instance of NackClass.



67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# File 'lib/mega/nack.rb', line 67

def initialize(error=nil, *data, &ctrl)
  if Class === error and error <= Exception
    @error = error.new(*data)
  elsif error.kind_of?( Exception )
    @error = error
  elsif error.kind_of?( String )
    @error = StandardError.new(error)
  elsif error == nil
    @error = StandardError.new
  else
    raise InvalidNackError
  end
  @data = data
  @ctrl = ctrl
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(meth, *args) ⇒ Object



101
102
103
# File 'lib/mega/nack.rb', line 101

def method_missing(meth, *args)
  raise_error
end

Instance Attribute Details

#dataObject (readonly)

Returns the value of attribute data.



65
66
67
# File 'lib/mega/nack.rb', line 65

def data
  @data
end

#errorObject (readonly)

Returns the value of attribute error.



65
66
67
# File 'lib/mega/nack.rb', line 65

def error
  @error
end

Instance Method Details

#==(x) ⇒ Object



97
98
99
# File 'lib/mega/nack.rb', line 97

def ==(x)
  x.is_a?(NackClass)
end

#call(*args) ⇒ Object



83
84
85
# File 'lib/mega/nack.rb', line 83

def call(*args)
  @ctrl.call(*args)
end

#call_with_dataObject



87
88
89
# File 'lib/mega/nack.rb', line 87

def call_with_data
  @ctrl.call(*@data)
end

#raise_errorObject

Raises:



91
92
93
# File 'lib/mega/nack.rb', line 91

def raise_error
  raise @error
end

#to_sObject



95
# File 'lib/mega/nack.rb', line 95

def to_s; "n/a"; end