Class: DataContract::Contract
- Inherits:
-
Object
- Object
- DataContract::Contract
- Defined in:
- lib/data_contract/contract.rb
Instance Attribute Summary collapse
-
#mod ⇒ Object
readonly
Returns the value of attribute mod.
Instance Method Summary collapse
- #assignable?(other_obj) ⇒ Boolean
- #compatible?(other_obj) ⇒ Boolean
- #getters ⇒ Object
-
#initialize(mod) ⇒ Contract
constructor
A new instance of Contract.
- #setters ⇒ Object
- #shared?(other_obj) ⇒ Boolean
Constructor Details
#initialize(mod) ⇒ Contract
Returns a new instance of Contract.
5 6 7 |
# File 'lib/data_contract/contract.rb', line 5 def initialize(mod) @mod = mod end |
Instance Attribute Details
#mod ⇒ Object (readonly)
Returns the value of attribute mod.
3 4 5 |
# File 'lib/data_contract/contract.rb', line 3 def mod @mod end |
Instance Method Details
#assignable?(other_obj) ⇒ Boolean
28 29 30 31 32 33 34 35 |
# File 'lib/data_contract/contract.rb', line 28 def assignable?(other_obj) unless shared? other_obj unless compatible? other_obj return false end end true end |
#compatible?(other_obj) ⇒ Boolean
17 18 19 20 21 22 |
# File 'lib/data_contract/contract.rb', line 17 def compatible?(other_obj) mod.instance_methods(false).each do |m| return false unless other_obj.respond_to? m end return true end |
#getters ⇒ Object
13 14 15 |
# File 'lib/data_contract/contract.rb', line 13 def getters mod.instance_methods(false).select { |m| m.to_s[-1, 1] != '=' } end |
#setters ⇒ Object
9 10 11 |
# File 'lib/data_contract/contract.rb', line 9 def setters mod.instance_methods(false).select { |m| m.to_s[-1, 1] == '=' } end |
#shared?(other_obj) ⇒ Boolean
24 25 26 |
# File 'lib/data_contract/contract.rb', line 24 def shared?(other_obj) other_obj.is_a? mod end |