Class: Dhallish::Ast::RecordProjection
- Inherits:
-
Object
- Object
- Dhallish::Ast::RecordProjection
- Defined in:
- lib/ast.rb
Overview
keys: ruby-list of keys to access (strings)
Instance Attribute Summary collapse
-
#keys ⇒ Object
Returns the value of attribute keys.
-
#rec ⇒ Object
Returns the value of attribute rec.
Instance Method Summary collapse
- #compute_type(ctx) ⇒ Object
- #evaluate(ctx) ⇒ Object
-
#initialize(rec, keys) ⇒ RecordProjection
constructor
A new instance of RecordProjection.
Constructor Details
#initialize(rec, keys) ⇒ RecordProjection
Returns a new instance of RecordProjection.
466 467 468 469 |
# File 'lib/ast.rb', line 466 def initialize(rec, keys) @rec = rec @keys = keys end |
Instance Attribute Details
#keys ⇒ Object
Returns the value of attribute keys.
465 466 467 |
# File 'lib/ast.rb', line 465 def keys @keys end |
#rec ⇒ Object
Returns the value of attribute rec.
464 465 466 |
# File 'lib/ast.rb', line 464 def rec @rec end |
Instance Method Details
#compute_type(ctx) ⇒ Object
471 472 473 474 475 476 477 478 479 480 |
# File 'lib/ast.rb', line 471 def compute_type(ctx) rectype = @rec.compute_type ctx assert("`.` can only be used on records") { rectype.is_a? Types::Record } newrectype = {} @keys.each { |key| assert("missing key in projection: `#{key}`") { !rectype.types[key].nil? } newrectype[key] = rectype.types[key] } Types::Record.new(newrectype) end |
#evaluate(ctx) ⇒ Object
482 483 484 485 486 487 488 489 |
# File 'lib/ast.rb', line 482 def evaluate(ctx) rec = @rec.evaluate ctx newrecvals = {} @keys.each { |key| newrecvals[key] = rec[key] } newrecvals end |