Personal Development
The Passionate Programmer
Ruby
The Ruby Programming Language - David Flanagan, Yukihiro Matsumoto
Programming Ruby 1.9 - Dave Thomas, Chad Fowler, Andy Hunt
Personal Development
The Passionate Programmer
Ruby
The Ruby Programming Language - David Flanagan, Yukihiro Matsumoto
Programming Ruby 1.9 - Dave Thomas, Chad Fowler, Andy Hunt
| HOW TO USE | |
| ========== | |
| COMMAND LINE | |
| ============= | |
| spec --color --format specdoc user.rspec | |
| RAILS | |
| ============= | |
| ./script/generate rspec_model User |
| # RSpec 2.0 syntax Cheet Sheet | |
| # Задаем спек внутри модуля Игрок, рспек автоматически подхватит Player::MovieList как переменную 'subject' (смотри ниже) | |
| module Player | |
| describe MovieList, "с необязательным описанием" do | |
| it "этот пример находится в ожидании(pending) поэтому можно написать его побырому" | |
| it "это уже рабочий пример, но он не будет красным а желтым, потому что мы его замарозим" do | |
| pending("пендинг все обрывает, но не помечает красным") |
| --- | |
| rspec_shoulda: | | |
| Shoulda Rspec Matchers | |
| For more information on rspec, rspec-rails, shoulda | |
| $ cheat rspec | |
| $ cheat rspec_on_rails_matchers | |
| $ cheat shoulda | |
| Models Matchers | |
| Data |
| ; Stumbling towards Y (Clojure Version) | |
| ; | |
| ; (this tutorial can be cut & pasted into your IDE / editor) | |
| ; | |
| ; The applicative-order Y combinator is a function that allows one to create a | |
| ; recursive function without using define. | |
| ; This may seem strange, because usually a recursive function has to call | |
| ; itself, and thus relies on itself having been defined. | |
| ; | |
| ; Regardless, here we will stumble towards the implementation of the Y combinator. |
| ;; A Simplifier for all Expressions | |
| ;; Example: | |
| ;; (simplify '(* 1 (+ x (- y y)))) ;=> x | |
| ;; (simplify '(and a (and (and) b))) ;=> (and a b) | |
| ;; See section 4.4, "Syntactic Abstraction" of Norvig and Pitman's | |
| ;; "Tutorial on Good Lisp Programming Style": | |
| ;; http://norvig.com/luv-slides.ps |
| ;----------------------------------------------------------------------------------- | |
| ; 1 - example of simple operations | |
| ;----------------------------------------------------------------------------------- | |
| ; arithmatic operations | |
| (+ 1 2) | |
| (* 2 3) | |
| (/ 8 2) | |
| (> 4 3) | |
| (= 4 6) |
| For each Ruby module/class, we have Ruby methods on the left and the equivalent | |
| Clojure functions and/or relevant notes are on the right. | |
| For clojure functions, symbols indicate existing method definitions, in the | |
| clojure namespace if none is explicitly given. clojure.contrib.*/* functions can | |
| be obtained from http://github.com/kevinoneill/clojure-contrib/tree/master, | |
| ruby-to-clojure.*/* functions can be obtained from the source files in this | |
| gist. | |
| If no method symbol is given, we use the following notation: |
| (ns sunil.curry) | |
| (defn partial+ | |
| "Takes a function f and fewer than the normal arguments to f, and | |
| returns a fn that takes a variable number of additional args. When | |
| called, the returned function calls f with args + additional args. | |
| differs from the core version in that it works on just one argument." | |
| {:added "1.0"} | |
| ([f] f) | |
| ([f arg1] |
| (defmacro def-curry-fn [name args & body] | |
| {:pre [(not-any? #{'&} args)]} | |
| (if (empty? args) | |
| `(defn ~name ~args ~@body) | |
| (let [rec-funcs (reduce (fn [l v] | |
| `(letfn [(helper# | |
| ([] helper#) | |
| ([x#] (let [~v x#] ~l)) | |
| ([x# & rest#] (let [~v x#] | |
| (apply (helper# x#) rest#))))] |