Class: Trith::Function
- Inherits:
-
Object
- Object
- Trith::Function
- Defined in:
- lib/trith/function.rb
Overview
A Trith function.
Constant Summary
- URI =
RDF::URI("http://trith.org/lang/Function").freeze
Instance Attribute Summary (collapse)
Instance Method Summary (collapse)
- - (Enumerator) each_statement(&block)
-
- (Function) initialize(id = nil, options = {}, &block)
constructor
A new instance of Function.
-
- (String) inspect
Returns a developer-friendly representation of this function.
-
- (Boolean) is_primitive?
(also: #is_native?)
Returns
trueif this is a primitive function. - - (Enumerable<Symbol>) labels
-
- (RDF::Graph) to_rdf
Returns the RDF representation of this function.
Constructor Details
- (Function) initialize(id = nil, options = {}, &block)
A new instance of Function
18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/trith/function.rb', line 18 def initialize(id = nil, = {}, &block) @id = case id when nil then RDF::Node.new when RDF::Resource then id else RDF::Resource.new(id) end if block_given? case block.arity when 1 then block.call(self) else self.instance_eval(&block) end end end |
Instance Attribute Details
- (String) comment
14 15 16 |
# File 'lib/trith/function.rb', line 14 def comment @comment end |
- (RDF::Resource) id
8 9 10 |
# File 'lib/trith/function.rb', line 8 def id @id end |
- (Symbol) label
11 12 13 |
# File 'lib/trith/function.rb', line 11 def label @label ||= id.to_s.sub(/^(.*)\/([^\/]+)$/, '\2').to_sym # FIXME end |
Instance Method Details
- (Enumerator) each_statement(&block)
80 81 82 |
# File 'lib/trith/function.rb', line 80 def each_statement(&block) to_rdf.each_statement(&block) end |
- (String) inspect
Returns a developer-friendly representation of this function.
62 63 64 |
# File 'lib/trith/function.rb', line 62 def inspect sprintf("#<%s:%#0x(%s)>", self.class.name, __id__, id.to_s) end |
- (Boolean) is_primitive? Also known as: is_native?
Returns true if this is a primitive function.
Primitive functions are implemented directly in the Trith interpreter or compiler using native code.
52 53 54 |
# File 'lib/trith/function.rb', line 52 def is_primitive? false # TODO end |
- (Enumerable<Symbol>) labels
41 42 43 |
# File 'lib/trith/function.rb', line 41 def labels [label] # FIXME end |
- (RDF::Graph) to_rdf
Returns the RDF representation of this function.
70 71 72 73 74 75 76 |
# File 'lib/trith/function.rb', line 70 def to_rdf RDF::Graph.new(id) do |graph| graph << [id, RDF.type, Trith::Function::URI] graph << [id, RDF::RDFS.label, label] if label graph << [id, RDF::RDFS.comment, label] if comment end end |