Class: Mal::ObjectT

Inherits:
OnlyT
  • Object
show all
Defined in:
lib/mal.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from OnlyT

#|

Constructor Details

#initialize(*supported_methods) ⇒ ObjectT

Returns a new instance of ObjectT.



121
122
123
# File 'lib/mal.rb', line 121

def initialize(*supported_methods)
  @supported_methods = supported_methods.map(&:to_sym)
end

Instance Attribute Details

#supported_methodsObject (readonly)

Returns the value of attribute supported_methods.



120
121
122
# File 'lib/mal.rb', line 120

def supported_methods
  @supported_methods
end

Instance Method Details

#&(another) ⇒ Object



136
137
138
139
140
141
# File 'lib/mal.rb', line 136

def &(another)
  if another.is_a?(ObjectT)
    methods_of_both = (@supported_methods + another.supported_methods).uniq
    ObjectT.new(*methods_of_both)
  end
end

#===(value) ⇒ Object



125
126
127
128
129
130
# File 'lib/mal.rb', line 125

def ===(value)
  @supported_methods.each do |m|
    return false unless value.respond_to?(m)
  end
  true
end

#inspectObject



132
133
134
# File 'lib/mal.rb', line 132

def inspect
  'ObjectWith(%s)' % @supported_methods.map(&:inspect).join(', ')
end