Top Level Namespace

Defined Under Namespace

Classes: Array, Date, Document, FileName, Hash, Integer, Object, Parser, Rule, RuleSet, Stack, String, Time, Token, Value

Instance Method Summary collapse

Instance Method Details

#assert(cond, msg = 'Error!') ⇒ Object


5
6
7
# File 'lib/basic/basic.rb', line 5

def assert cond, msg = 'Error!'
	if !cond then raise msg end
end

#check_args(var, type) ⇒ Object


13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/basic/basic.rb', line 13

def check_args var, type
	if var.class != Array then var = [var] end
	if type.class != Array then type = [type] end

	assert (var.length == type.length), 'array lengths must match'

	ctr = 0
	while ctr < var.length
		var[ctr].assert_type type[ctr]
		ctr += 1
	end
end

#error(msg = 'Error!') ⇒ Object


9
10
11
# File 'lib/basic/basic.rb', line 9

def error msg = 'Error!'
	assert false, msg
end

#write_file(filename = nil) ⇒ Object


73
74
75
76
77
78
# File 'lib/basic/basic.rb', line 73

def write_file filename = nil
	file = filename ? File.open( filename, 'w' ) : Tempfile.new( filename )

	file.print yield
	file.close
end