Class: Object

Inherits:
BasicObject
Defined in:
lib/RubyExt/assert.rb,
lib/RubyExt/object.rb,
lib/RubyExt/Localization/Object.rb

Instance Method Summary collapse

Instance Method Details

#selfObject



2
# File 'lib/RubyExt/object.rb', line 2

def self; self end

#should!(cmd, arg = NotDefined) ⇒ Object



2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/RubyExt/assert.rb', line 2

def should! cmd, arg = NotDefined
	result = case cmd								
		when :be_never_called then false
		
		when :be_nil then self.equal? nil		
		
		when :be_a
		if arg.class == Array
			arg.any?{|klass| self.is_a? klass}
		else
			self.is_a? arg
		end
		
		when :be			
		if arg.class == Array
			arg.any?{|klass| self.respond_to :is?, klass}
		else
			self.respond_to :is?, arg
		end
		
		when :include then self.include? arg
		
		when :be_in then arg.include? self
		
		when :be_true then self
		
	when :be_false then !self
		
		when :be_empty then self.empty?
		
	else
		if arg.equal? NotDefined
			self.send cmd
		else
			self.send cmd, arg
		end						
	end
	
	unless result
		unless arg.equal? NotDefined
			raise RuntimeError,  "				
ASSERTION FAILED:
#{self.inspect} should #{cmd} #{arg.inspect}
", caller
		else
			raise RuntimeError,  "				
ASSERTION FAILED:
#{self.inspect} should #{cmd}
", caller
		end
	end		
	
	return self
end

#should_not!(cmd, arg = NotDefined) ⇒ Object



57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
# File 'lib/RubyExt/assert.rb', line 57

def should_not! cmd, arg = NotDefined
	result = case cmd								
		when :be_never_called then false
		
		when :be_nil then self.equal? nil
		
		when :be_a
		if arg.class == Array
			arg.any?{|klass| self.is_a? klass}
		else
			self.is_a? arg
		end
		
		when :be			
		if arg.class == Array
			arg.any?{|klass| self.respond_to :is?, klass}
		else
			self.respond_to :is?, arg
		end
		
		when :include then self.include? arg
		
		when :be_in then arg.include? self
		
		when :be_true then self
		
	when :be_false then !self
		
		when :be_empty then self.empty?
		
	else
		if arg.equal? NotDefined
			self.send cmd
		else
			self.send cmd, arg
		end						
	end
	
	if result
		unless arg.equal? NotDefined
			raise RuntimeError,  "				
ASSERTION FAILED:
#{self.inspect} should not #{cmd} #{arg.inspect}
", caller
		else
			raise RuntimeError,  "				
ASSERTION FAILED:
#{self.inspect} should not #{cmd}
", caller
		end
	end
	
	return self
end

#to_l(string, binding = nil) ⇒ Object



2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/RubyExt/Localization/Object.rb', line 2

def to_l string, binding = nil
	lang = RubyExt::Localization.language
	unless lang == RubyExt::Localization::DEFAULT_LANGUAGE
		aself = self.respond_to(:localization_self) || self
		aclass = (aself.class == Class or aself.class == Module) ? aself : aself.class						
		
		localization = aclass.localization lang
		if localization and localization.include? string
			string = localization[string]
		else				
			RubyExt::Localization.log.warn("Not localized: '#{aclass.name}' '#{string}'!")
		end		
	end
	
	string = string.substitute binding if binding
	return string
end