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 Parent | |
class << self | |
def children | |
@children ||= [] | |
end | |
def inherited(cls) | |
children << cls | |
end | |
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
module ConcernedParent | |
module ClassMethods | |
def children | |
@children ||= [] | |
end | |
def inherited(cls) | |
children << cls | |
end | |
end | |
def self.included(cls) |
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
(defn reject-multiples | |
"A function that rejects multiples of n." | |
[n] | |
(fn [x] (not (zero? (mod x n))))) | |
(defn primes | |
"An infinite sequence of prime numbers" | |
([] (primes (iterate inc 2))) | |
([seq] | |
(let [head (first seq)] |
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 = File.join( | |
Config::CONFIG['bindir'], | |
Config::CONFIG['ruby_install_name'] + Config::CONFIG['EXEEXT']). | |
sub(/.*\s.*/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
; Church Numerals in Clojure | |
; | |
; Church numerals use anonymous functions to represent numbers. | |
; | |
; ((zero f) x) -- returns x | |
; ((one f) x) -- return (f x) | |
; ((two f) x) -- return (f (f x)) | |
; ... | |
(def zero (fn [f] (fn [x] x))) |
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
%w(some_method some_other_method).each do |method| | |
it "should call #{method}" do | |
obj.should_receive(:some_method).once | |
test_code_here | |
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
[Object|should_receive();new_instances();flexmock_get();flexmock_teardown();flexmock_verify()] | |
[Object]obj<->flexmock_proxy[PartialMockProxy|should_receive()] | |
[PartialMockProxy]->mock[Mock|should_receive()] | |
[Object]<-[note:These 5 methods are dynamically added to a partially mocked object] | |
[PartialMockProxy]<-[note:Proxies mediate between the mock and object] | |
[Mock]<-[note:Regular mock object. Knows nothing about proxies or real object.] |
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
;; Exercise 1.1. Below is a sequence of expressions. What is the | |
;; result printed by the interpreter in response to each expression? | |
;; Assume that the sequence is to be evaluated in the order in which | |
;; it is presented. | |
;; 10 | |
;; => 10 | |
;; (+ 5 3 4) | |
;; => 12 |
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
;; SICP Exercise 1.2: | |
;; Translate the following expression into prefix form | |
(/ (+ 5 4 (- 2 (- 3 (+ 6 (/ 1 5))))) | |
(* 3 (- 6 2) (- 2 7)) ) | |
;; => -71/300 | |
;; or -0.236666666666667 |
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
;; SICP 1.3 | |
;; Exercise 1.3. Define a procedure that takes three numbers as | |
;; arguments and returns the sum of the squares of the two larger | |
;; numbers. | |
(define (square x) (* x x)) | |
(define (sum-of-squares a b) | |
(+ (square a) (square b)) ) |