Module: Rubylog::Context

Overview

You can use this to access Rubylog in the command line or in the main object.

For example,

require 'rubylog'
extend Rubylog::Context

solve A.is(5).and { puts A; true }

You can also use this to convert any object to a context.

You can extend Rubylog::Context to modules or classes.

class A

extend Rubylog::Context
predicate ".good"

end

This automatically uses the class as default subject.

Finally, you can include it to a class.

class MyContext

include Rubylog::Context

end

myc = MyContext.new myc.predicate_for A, “.bad”

Instance Attribute Summary

Attributes included from Rubylog::ContextModules::Predicates

#default_subject

Class Method Summary collapse

Methods included from Rubylog::ContextModules::Thats

#thats, #thats_not

Methods included from Rubylog::ContextModules::Primitives

#primitives, #primitives_for, #primitives_for_context

Methods included from Rubylog::ContextModules::Predicates

#predicate, #predicate_for, #predicate_for_context

Methods included from Rubylog::ContextModules::Demonstration

#solve, #true?

Methods included from Rubylog::ContextModules::Checks

#check, #check_failed, #check_passed, #check_raised_exception

Class Method Details

.extended(context) ⇒ Object



46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/rubylog/context_creation.rb', line 46

def self.extended context
  # We include DSL::Variables in its singleton class
  class << context
    include Rubylog::DSL::Variables
  end

  if context.is_a? Module
    # if context is a class or module, we also include DSL::Variables directly
    # in it, so that they can be accessed in class_eval mode or from an
    # instance method.
    context.send :include, Rubylog::DSL::Variables

    # Also, we set self as a subject, so that +predicate+ automatically attaches
    # functors to the class.
    context.default_subject = context
  end
end

.included(class_or_module) ⇒ Object



64
65
66
# File 'lib/rubylog/context_creation.rb', line 64

def self.included class_or_module
  class_or_module.send :include, Rubylog::DSL::Variables
end