Skip to content

Instantly share code, notes, and snippets.

@robertodecurnex
Created January 14, 2015 18:24
Show Gist options
  • Save robertodecurnex/96e716af5c5ebff0ab1d to your computer and use it in GitHub Desktop.
Save robertodecurnex/96e716af5c5ebff0ab1d to your computer and use it in GitHub Desktop.
class Sample
def hello name
# sc
end
def sum n1, n2
# sc sum n1, n2
end
def rule_of_three a, b, c
# sc multiply c, b {|x| divide x, a }
end
end
__END__
sc hello String -> String
"Minion" -> "Say Hello to Minion"
"Roberto" -> "Say Hello to Roberto"
"Roland" -> "Say Hello to Roland"
sc sum Fixnum, Fixnum -> Fixnum
1, 1 -> 2
1, 2 -> 3
2, 2 -> 4
sc multiply Float, Float -> Float
1.0, 1.0 -> 1.0
1.0, 2.0 -> 2.0
2.0, 2.0 -> 4.0
sc divide Float, Float -> Float
1.0, 1.0 -> 1.0
2.0, 1.0 -> 2.0
2.0, 2.0 -> 1.0
class Sample
include SC
implements hello: :name
implements \
sum: [:n1, :n2],
rule_of_three: [:a, :b, :c]
def double n1
self.sum(n1, n1)
end
end
__END__
spec_for hello String -> String
"Minion" -> "Say Hello to Minion"
"Roberto" -> "Say Hello to Roberto"
"Roland" -> "Say Hello to Roland"
spec_for sum Fixnum, Fixnum -> Fixnum
1, 1 -> 2
1, 2 -> 3
2, 2 -> 4
spec_for rule_of_three Float, Float, Float -> Float
1.0, 1.0, 2.0 -> 2.0
2.0, 4.0, 3.0 -> 6.0
10.0, 2.0, 3.0 -> 0.6
class Sample
include SC
implements hello: :name
implements \
sum: [:n1, :n2],
rule_of_three: [:a, :b, :c]
def double n1
self.sum(n1, n1)
end
end
describe Sample do
cs_spec_for '#hello String -> String' do
sample.hello('Minion').should == 'Say Hello to Minion'
sample.hello('Roberto').should == 'Say Hello to Roberto'
sample.hello('Roland').should == 'Say Hello to Roland'
end
cs_spec_for '#sum Fixnum, Fixnum -> Fixnum' do
sample.sum(1, 1).should == 2
sample.sum(1, 2).should == 3
sample.sum(2, 2).should == 4
end
cd_spec_for '#rule_of_three Float, Float, Float -> Float' do
sample.rule_of_three(1.0, 1.0, 2.0).should == 2.0
sample.rule_of_three(2.0, 4.0, 3.0).should == 6.0
sample.rule_of_three(10.0, 2.0, 3.0).should == 0.6
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment