Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Resolving compatibility issues with REE 1.8.6
- Loading branch information
Showing
21 changed files
with
415 additions
and
326 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
module ArrayExtensions | ||
def shuffle | ||
array = self.clone | ||
n = array.size | ||
while n > 1 do | ||
n-=1 | ||
k = Kernel.rand(n+1) | ||
tmp = array[k] | ||
array[k] = array[n] | ||
array[n] = tmp | ||
end | ||
array | ||
end #unless method_defined?(:shuffle) | ||
|
||
|
||
def shuffle! | ||
n = self.size | ||
while n > 1 do | ||
n-=1 | ||
k = Kernel.rand(n+1) | ||
tmp = self[k] | ||
self[k] = self[n] | ||
self[n] = tmp | ||
end | ||
|
||
end #unless method_defined?(:shuffle!) | ||
|
||
def comb(n = size) | ||
if size < n or n < 0 | ||
elsif n == 0 | ||
yield([]) | ||
else | ||
self[1..-1].comb(n) do |x| | ||
yield(x) | ||
end | ||
self[1..-1].comb(n - 1) do |x| | ||
yield([first] + x) | ||
end | ||
end | ||
end | ||
|
||
|
||
def combination(n = size) | ||
array = [] | ||
comb(n) {|c| array << c} | ||
array | ||
end | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
module EnumerableExtensions | ||
|
||
def max_by(&proc) | ||
max_obj = nil | ||
max_val = nil | ||
is_first = true | ||
each do |obj| | ||
val = proc.call(obj) | ||
if is_first || val > max_val | ||
max_obj = obj | ||
max_val = val | ||
end | ||
is_first = false | ||
end | ||
max_obj | ||
end | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.