Class: RubyBreaker::TypeDefs::DuckType

Inherits:
Type
  • Object
show all
Defined in:
lib/rubybreaker/type/type.rb

Overview

This class represents any object with certain methods Usage: [m1,m2,…] where m1…mn are method names

Direct Known Subclasses

FusionType

Instance Attribute Summary collapse

Attributes inherited from Type

#ctx

Instance Method Summary collapse

Methods inherited from Type

#eql?, #subtype_of?, #unparse

Constructor Details

#initialize(meth_names = [], *args) ⇒ DuckType

Returns a new instance of DuckType.



122
123
124
125
# File 'lib/rubybreaker/type/type.rb', line 122

def initialize(meth_names=[],*args)
  super(*args)
  @meth_names = meth_names.map!{|n| n.to_sym}
end

Instance Attribute Details

#meth_namesObject

This accessor sets/gets method names in the duck type.



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

def meth_names
  @meth_names
end

Instance Method Details

#add_meth(meth_name) ⇒ Object



126
127
128
# File 'lib/rubybreaker/type/type.rb', line 126

def add_meth(meth_name)
  @meth_names << meth_name.to_sym if !@meth_names.include?(meth_name)
end