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
class Array | |
def count_if | |
inject(0) {|acc, i| acc + (yield(i) ? 1 : 0) } | |
end | |
end | |
def f(ra,n) | |
ra.count_if {|x| x.include? n } | |
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
#Ruby assignment option to assign unless nil | |
replacement_content = page_contents.content_label_find(item) | |
########################################################## | |
# The following is wrong, see http://gist.github.com/68772 | |
########################################################## | |
# This | |
element.inner_html = replacement_content if replacement_content |
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 from Mitchell | |
def self.first_uninteresting | |
all_numbers = Number.find(:all).map { |entry| entry.number }.sort | |
last = 0 | |
all_numbers.each do |number| | |
if number != last + 1 | |
return last + 1 | |
end | |
last = number |
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
class Object | |
def new_with &block | |
self.new.instance_eval { | |
yield | |
} | |
end | |
end | |
$logger = Object.new_with { | |
define_method :foo do |
NewerOlder