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
diff --git a/app/models/sample.rb b/app/models/sample.rb | |
new file mode 100644 | |
index 0000000..7d523a9 | |
--- /dev/null | |
+++ b/app/models/sample.rb | |
@@ -0,0 +1,3 @@ | |
+class Sample < ActiveRecord::Base | |
+ validates_presence_of :value | |
+end | |
diff --git a/db/migrate/20090522160717_create_samples.rb b/db/migrate/20090522160717_create_samples.rb |
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 Basket < Struct.new(:entries) | |
def self.new(*args) | |
b = super(*args) | |
b.entries ||= [] | |
b | |
end | |
def total | |
entries.inject(0.0) do |sum, entry| |
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
(?<group-name>regular-expression){0} |
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
\g<group-name> |
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
(?<ltr>[ABCEGHJKLMNPRSTVXYWZ]){0} | |
(?<num>[0-9]){0} | |
(?<fsa>\g<ltr>\g<num>\g<ltr>){0} | |
(?<ldu>\g<num>\g<ltr>\g<num>){0} | |
(?<cpc>\g<fsa> \g<ldu>){0} | |
^\d{5}|\g<cpc>$ |
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-1.9.3-p0 :001 > def f(x, y=1) | |
ruby-1.9.3-p0 :002?> method(__method__).parameters | |
ruby-1.9.3-p0 :003?> end | |
=> nil | |
ruby-1.9.3-p0 :004 > f(1, 2) | |
=> [[:req, :x], [:opt, :y]] |
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
module M | |
def hello | |
1 | |
end | |
end | |
module N | |
include M |
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
module M | |
def method | |
puts "hello" | |
end | |
end | |
def execute(current_module, &block) | |
Object.new.tap do |o| | |
o.extend(current_module) | |
o.instance_eval &block |
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
p = lambda { |x| | |
x * 2 | |
} | |
p === 7 #=> 14 |
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 Deferrable < SimpleDelegator | |
# Public: Create a side thread that wraps whatever you need to have available in the future. | |
def initialize(&blk) | |
super(Thread.new(&blk)) | |
end | |
# Internal: We need the result of the computation of this thread NOW, so block on it and return | |
# the value. | |
def __getobj__ |
OlderNewer