Module: Contracts::Support
- Defined in:
- lib/contracts/support.rb
Class Method Summary collapse
- .eigenclass?(target) ⇒ Boolean
- .eigenclass_hierarchy_supported? ⇒ Boolean
- .eigenclass_of(target) ⇒ Object
- .method_name(method) ⇒ Object
- .method_position(method) ⇒ Object
-
.unique_id ⇒ Object
Generates unique id, which can be used as a part of identifier.
Class Method Details
.eigenclass?(target) ⇒ Boolean
40 41 42 |
# File 'lib/contracts/support.rb', line 40 def self.eigenclass?(target) target <= eigenclass_of(Object) end |
.eigenclass_hierarchy_supported? ⇒ Boolean
31 32 33 34 |
# File 'lib/contracts/support.rb', line 31 def self.eigenclass_hierarchy_supported? return false if RUBY_PLATFORM == "java" && RUBY_VERSION.to_f < 2.0 RUBY_VERSION.to_f > 1.8 end |
.eigenclass_of(target) ⇒ Object
36 37 38 |
# File 'lib/contracts/support.rb', line 36 def self.eigenclass_of(target) class << target; self; end end |
.method_name(method) ⇒ Object
18 19 20 |
# File 'lib/contracts/support.rb', line 18 def self.method_name(method) method.is_a?(Proc) ? "Proc" : method.name end |
.method_position(method) ⇒ Object
3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
# File 'lib/contracts/support.rb', line 3 def self.method_position(method) return method.method_position if method.is_a?(MethodReference) if RUBY_VERSION =~ /^1\.8/ if method.respond_to?(:__file__) method.__file__ + ":" + method.__line__.to_s else method.inspect end else file, line = method.source_location file + ":" + line.to_s end end |
.unique_id ⇒ Object
26 27 28 29 |
# File 'lib/contracts/support.rb', line 26 def self.unique_id # Consider using SecureRandom.hex here, and benchmark which one is better (Time.now.to_f * 1000).to_i.to_s(36) + rand(1_000_000).to_s(36) end |