Class: Cyc::Builder
- Inherits:
-
Object
- Object
- Cyc::Builder
- Defined in:
- lib/cyc/builder.rb
Overview
This class is used to capture calls to the Cyc client, to allow nested calls, like
cyc.with_any_mt do |cyc|
cyc.comment :Collection
end
Instance Method Summary collapse
-
#initialize ⇒ Builder
constructor
A new instance of Builder.
- #method_missing(name, *args, &block) ⇒ Object
- #reset ⇒ Object
- #to_cyc ⇒ Object
Constructor Details
#initialize ⇒ Builder
Returns a new instance of Builder.
9 10 11 |
# File 'lib/cyc/builder.rb', line 9 def initialize reset end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *args, &block) ⇒ Object
21 22 23 24 25 26 27 28 |
# File 'lib/cyc/builder.rb', line 21 def method_missing(name,*args,&block) @query << "(" << name.to_s.gsub("_","-") << " " @query << (args||[]).map{|a| a.to_cyc}.join(" ") if block block.call(self) end @query << ")" end |
Instance Method Details
#reset ⇒ Object
13 14 15 |
# File 'lib/cyc/builder.rb', line 13 def reset @query = "" end |
#to_cyc ⇒ Object
17 18 19 |
# File 'lib/cyc/builder.rb', line 17 def to_cyc @query end |