CSV is built into Ruby 1.9

In Ruby 1.9, fasterCSV has been made the implementation of the stdlib
CSV, so we remove the rubygems (which btw, is also
included by default in 1.9) and just make require 'csv' and CSV
instead of FasterCSV.

http://ruby-doc.org/stdlib/libdoc/csv/rdoc/index.html

the return of JSON parse is not string

require ‘json’

>> a={“use”=>false}
=> {“use”=>false}
>> b=a.to_json
=> “{\”use\”:false}”
>> c=JSON.parse b
=> {“use”=>false}
>> if not c[“use”]
>> puts “json parse gives true and false boolean values”
>> end
json parse gives true and false boolean values
=> nil

lunch bag

nslookup google.com

“foo”.object_id

“foo”.methods

guest = Object.new; def gues.t.name “guest” end

s=”foo”; s<<“d”; s.length => 4

protocol: TCP, HTTP

inheritance include inheritance of implementation and type. But the inheritance of type does not help because ruby is dynamic typing. When we talk about dynamic typing, we talk about a mechanism where the type of a variable can change and be resolved on the fly at the exact moment it gets parsed by the interpreter. When we talk about static typing, we talk about a mechanism where the type of a variable is resolved in advance by the interpreter/compiler. Javascript is dynamically typed too.

A dynamically typed language is a language where the type of a variable can be altered at any time. (It is a string, now it is a Fixnum, now it is a Time object, etc.)

A statically typed language is the opposite. (Decide what x is once for all and don’t change your mind!)

A strongly typed language is a language that is being strict about what you can do with your typed variables. (Don’t mix them… or I will throw you an error in the face!)

A weakly typed language is the opposite. (Do what you want with your different types. Mix them all! We’ll see what happens!)

http://www.rubyfleebie.com/ruby-is-dynamically-and-strongly-typed/

delegation means composition in ruby but means prototypes in Javascript.

validate_with

validate { |r| r.home_phone? || r.cell_phone? } # validate it should be either a home phone or a cell phone.

polymorphism: method lookup is fast, but testing class type is slow and messy.

object reference in ruby

you pass the value of the variable in to the method, however the value of the
variable is _always_ a reference to an object.

In order to get a object that won’t change out from under you, you need to dup or clone the object you’re passed, thus giving an object that nobody else has a reference to.

b=[]
=> []
>> a=b
=> []
>> b< <1
>> a
=> [1]

__FILE

__FILE__ is the filename with extension of the file containing the code being executed.

In foo.rb, __FILE__ would be “foo.rb”.

If foo.rb were in the dir /home/josh then File.dirname(__FILE__) would return /home/josh

&& and || in ruby

&& return the first value that is false

&& returns the last value if all are true

irb(main):017:0> 1 && false && 2=> false
irb(main):018:0> 1 && 3 && 2 => 2
irb(main):019:0> 1 && nil && 3=> nil

|| is the opposite of &&

|| returns the first value that is ture; and if all values are false, return the last value

This way makes we can use ||= and &&=