Class: RubyProlog::Goal
- Inherits:
-
Object
- Object
- RubyProlog::Goal
- Defined in:
- lib/ruby-prolog/ruby-prolog.rb
Instance Attribute Summary collapse
-
#args ⇒ Object
readonly
Returns the value of attribute args.
-
#pred_id ⇒ Object
readonly
Returns the value of attribute pred_id.
-
#pred_name ⇒ Object
readonly
Returns the value of attribute pred_name.
Instance Method Summary collapse
-
#initialize(pred_id, pred_name, args) ⇒ Goal
constructor
A new instance of Goal.
- #inspect ⇒ Object
- #to_prolog ⇒ Object
Constructor Details
#initialize(pred_id, pred_name, args) ⇒ Goal
Returns a new instance of Goal.
110 111 112 |
# File 'lib/ruby-prolog/ruby-prolog.rb', line 110 def initialize(pred_id, pred_name, args) @pred_id, @pred_name, @args = pred_id, pred_name, args end |
Instance Attribute Details
#args ⇒ Object (readonly)
Returns the value of attribute args.
108 109 110 |
# File 'lib/ruby-prolog/ruby-prolog.rb', line 108 def args @args end |
#pred_id ⇒ Object (readonly)
Returns the value of attribute pred_id.
108 109 110 |
# File 'lib/ruby-prolog/ruby-prolog.rb', line 108 def pred_id @pred_id end |
#pred_name ⇒ Object (readonly)
Returns the value of attribute pred_name.
108 109 110 |
# File 'lib/ruby-prolog/ruby-prolog.rb', line 108 def pred_name @pred_name end |
Instance Method Details
#inspect ⇒ Object
114 115 116 |
# File 'lib/ruby-prolog/ruby-prolog.rb', line 114 def inspect return @pred_name.to_s + @args.inspect.to_s end |
#to_prolog ⇒ Object
118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 |
# File 'lib/ruby-prolog/ruby-prolog.rb', line 118 def to_prolog args_out = @args.map do |arg| case arg when Symbol if arg == :_ "_" elsif /[[:upper:]]/.match(arg.to_s[0]) arg.to_s else "_#{arg.to_s}" end when String "'#{arg}'" when Cons, Goal arg.to_prolog when Numeric arg.to_s else raise "Unknown argument: #{arg.inspect}" end end.join(', ') if @pred_name == :not_ "\\+ #{args_out}" else "#{@pred_name}(#{args_out})" end end |