class Bio::Relation
Bio::Relation
is a simple object storing two nodes and the relation of them. The nodes and the edge (relation) can be any Ruby object. You can also compare Bio::Relation
objects if the edges have Comparable property.
Attributes
Public Class Methods
Source
# File lib/bio/pathway.rb 719 def initialize(node1, node2, edge) 720 @node = [node1, node2] 721 @edge = edge 722 end
Create new binary relation object consists of the two object ‘node1’ and ‘node2’ with the ‘edge’ object as the relation of them.
Public Instance Methods
Source
# File lib/bio/pathway.rb 774 def <=>(rel) 775 unless self.edge.kind_of? Comparable 776 raise "[Error] edges are not comparable" 777 end 778 if self.edge > rel.edge 779 return 1 780 elsif self.edge < rel.edge 781 return -1 782 elsif self.edge == rel.edge 783 return 0 784 end 785 end
Used by the each method to compare with another Bio::Relation
object. This method is only usable when the edge objects have the property of the module Comparable.
Source
# File lib/bio/pathway.rb 748 def ===(rel) 749 if self.edge == rel.edge 750 if self.node[0] == rel.node[0] and self.node[1] == rel.node[1] 751 return true 752 elsif self.node[0] == rel.node[1] and self.node[1] == rel.node[0] 753 return true 754 else 755 return false 756 end 757 else 758 return false 759 end 760 end
Compare with another Bio::Relation
object whether havind same edges and same nodes. The == method compares Bio::Relation
object’s id, however this case equality === method compares the internal property of the Bio::Relation
object.
Method eql? is an alias of the === method and is used with hash method to make uniq arry of the Bio::Relation
objects.
a1 = Bio::Relation.new('a', 'b', 1) a2 = Bio::Relation.new('b', 'a', 1) a3 = Bio::Relation.new('b', 'c', 1)
p [ a1, a2, a3 ].uniq
Source
# File lib/bio/pathway.rb 740 def hash 741 @node.sort.push(@edge).hash 742 end
Used by eql? method