Class: Steep::Interface::Shape::Methods
- Includes:
- Enumerable
- Defined in:
- lib/steep/interface/shape.rb
Instance Attribute Summary collapse
-
#methods ⇒ Object
readonly
Returns the value of attribute methods.
-
#resolved_methods ⇒ Object
readonly
Returns the value of attribute resolved_methods.
-
#substs ⇒ Object
readonly
Returns the value of attribute substs.
Instance Method Summary collapse
- #[](name) ⇒ Object
- #[]=(name, entry) ⇒ Object
- #each(&block) ⇒ Object
- #each_name(&block) ⇒ Object
-
#initialize(substs:, methods:) ⇒ Methods
constructor
A new instance of Methods.
- #key?(name) ⇒ Boolean
- #merge!(other, &block) ⇒ Object
- #public_methods ⇒ Object
- #push_substitution(subst) ⇒ Object
- #subst ⇒ Object
Constructor Details
#initialize(substs:, methods:) ⇒ Methods
105 106 107 108 109 |
# File 'lib/steep/interface/shape.rb', line 105 def initialize(substs:, methods:) @substs = substs @methods = methods @resolved_methods = {} end |
Instance Attribute Details
#methods ⇒ Object (readonly)
Returns the value of attribute methods.
101 102 103 |
# File 'lib/steep/interface/shape.rb', line 101 def methods @methods end |
#resolved_methods ⇒ Object (readonly)
Returns the value of attribute resolved_methods.
101 102 103 |
# File 'lib/steep/interface/shape.rb', line 101 def resolved_methods @resolved_methods end |
#substs ⇒ Object (readonly)
Returns the value of attribute substs.
101 102 103 |
# File 'lib/steep/interface/shape.rb', line 101 def substs @substs end |
Instance Method Details
#[](name) ⇒ Object
124 125 126 127 128 129 130 131 132 133 134 135 136 137 |
# File 'lib/steep/interface/shape.rb', line 124 def [](name) return nil unless key?(name) resolved_methods[name] ||= begin entry = methods.fetch(name) Entry.new( method_name: name, overloads: entry.overloads.map do |overload| overload.subst(subst) end, private_method: entry.private_method? ) end end |
#[]=(name, entry) ⇒ Object
119 120 121 122 |
# File 'lib/steep/interface/shape.rb', line 119 def []=(name, entry) resolved_methods[name] = nil methods[name] = entry end |
#each(&block) ⇒ Object
139 140 141 142 143 144 145 146 147 148 |
# File 'lib/steep/interface/shape.rb', line 139 def each(&block) if block methods.each_key do |name| entry = self[name] or next yield [name, entry] end else enum_for :each end end |
#each_name(&block) ⇒ Object
150 151 152 153 154 155 156 157 158 |
# File 'lib/steep/interface/shape.rb', line 150 def each_name(&block) if block each do |name, _| yield name end else enum_for :each_name end end |
#key?(name) ⇒ Boolean
111 112 113 114 115 116 117 |
# File 'lib/steep/interface/shape.rb', line 111 def key?(name) if entry = methods.fetch(name, nil) entry.has_method_type? else false end end |
#merge!(other, &block) ⇒ Object
172 173 174 175 176 177 178 179 180 |
# File 'lib/steep/interface/shape.rb', line 172 def merge!(other, &block) other.each do |name, entry| if block && (old_entry = methods[name]) methods[name] = yield(name, old_entry, entry) else methods[name] = entry end end end |
#public_methods ⇒ Object
182 183 184 185 186 187 |
# File 'lib/steep/interface/shape.rb', line 182 def public_methods Methods.new( substs: substs, methods: methods.reject {|_, entry| entry.private_method? } ) end |
#push_substitution(subst) ⇒ Object
168 169 170 |
# File 'lib/steep/interface/shape.rb', line 168 def push_substitution(subst) Methods.new(substs: [*substs, subst], methods: methods) end |
#subst ⇒ Object
160 161 162 163 164 165 166 |
# File 'lib/steep/interface/shape.rb', line 160 def subst @subst ||= begin substs.each_with_object(Substitution.empty) do |s, ss| ss.merge!(s, overwrite: true) end end end |