Skip to content
This repository has been archived by the owner on Oct 23, 2021. It is now read-only.

Commit

Permalink
use instance_eval and class_eval to add functionality within modules
Browse files Browse the repository at this point in the history
  • Loading branch information
rossta committed Apr 15, 2014
1 parent 9e29ec6 commit 4ef6255
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 10 deletions.
10 changes: 6 additions & 4 deletions lib/measurable/cosine.rb
Expand Up @@ -52,14 +52,16 @@ def cosine_distance(u, v)
end

def self.extended(base) # :nodoc:
base.extend Measurable::Euclidean

base.instance_eval do
extend Measurable::Euclidean
end
super
end

def self.included(base) # :nodoc:
base.include Measurable::Euclidean

base.class_eval do
include Measurable::Euclidean
end
super
end
end
Expand Down
8 changes: 2 additions & 6 deletions lib/measurable/tanimoto.rb
Expand Up @@ -31,23 +31,19 @@ def tanimoto(u, v)
end

def self.extended(base) # :nodoc:
base.extend Measurable::Jaccard

# Tanimoto similarity is the same as Jaccard similarity.
base.instance_eval do
extend Measurable::Jaccard
alias :tanimoto_similarity :jaccard
end

super
end

def self.included(base) # :nodoc:
base.include Measurable::Jaccard

base.class_eval do
include Measurable::Jaccard
alias :tanimoto_similarity :jaccard
end

super
end
end
Expand Down

0 comments on commit 4ef6255

Please sign in to comment.