Class: Qrb::System
- Inherits:
-
Object
- Object
- Qrb::System
- Defined in:
- lib/qrb/system.rb
Overview
A System is a collection of named Q types.
Instance Attribute Summary collapse
-
#main ⇒ Object
Returns the value of attribute main.
Instance Method Summary collapse
- #add_type(type) ⇒ Object
- #dress(*args, &bl) ⇒ Object
- #dup ⇒ Object
- #factory ⇒ Object
- #fetch(name, &bl) ⇒ Object
- #get_type(name) ⇒ Object (also: #[])
-
#initialize(types = {}, main = nil) ⇒ System
constructor
A new instance of System.
- #inspect ⇒ Object
- #parse(source) ⇒ Object
Constructor Details
#initialize(types = {}, main = nil) ⇒ System
Returns a new instance of System.
7 8 9 10 |
# File 'lib/qrb/system.rb', line 7 def initialize(types = {}, main = nil) @types = types @main = main end |
Instance Attribute Details
#main ⇒ Object
Returns the value of attribute main.
11 12 13 |
# File 'lib/qrb/system.rb', line 11 def main @main end |
Instance Method Details
#add_type(type) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/qrb/system.rb', line 19 def add_type(type) unless type.is_a?(Type) raise ArgumentError, "Qrb::Type expected, got `#{type}`" end if @types.has_key?(type.name) raise Error, "Duplicate type name `#{type.name}`" end @types[type.name] = type end |
#dress(*args, &bl) ⇒ Object
44 45 46 47 |
# File 'lib/qrb/system.rb', line 44 def dress(*args, &bl) raise Error, "No main type." unless main main.dress(*args, &bl) end |
#dup ⇒ Object
58 59 60 |
# File 'lib/qrb/system.rb', line 58 def dup System.new(@types.dup, @main) end |
#factory ⇒ Object
40 41 42 |
# File 'lib/qrb/system.rb', line 40 def factory @factory ||= TypeFactory.new end |
#fetch(name, &bl) ⇒ Object
36 37 38 |
# File 'lib/qrb/system.rb', line 36 def fetch(name, &bl) @types.fetch(name, &bl) end |
#get_type(name) ⇒ Object Also known as: []
31 32 33 |
# File 'lib/qrb/system.rb', line 31 def get_type(name) @types[name] end |
#inspect ⇒ Object
54 55 56 |
# File 'lib/qrb/system.rb', line 54 def inspect @types.each_pair.map{|k,v| "#{k} = #{v}" }.join("\n") end |
#parse(source) ⇒ Object
49 50 51 52 |
# File 'lib/qrb/system.rb', line 49 def parse(source) require "qrb/syntax" Syntax.compile(source, self.dup) end |