rod mclaughlinRuby Two's Day (27 jun 13)
http://www.ruby-lang.org/en/news/2013/02/24/ruby-2-0-0-p0-is-released/
Also, Rails Four: http://edgeguides.rubyonrails.org/4_0_release_notes.html
module Strings refine String do def bang "#{self}!" end end end begin s = "hello" puts s.bang rescue Exception => x puts "s.bang caused an error: "+x.message puts "trying s.bang, using module with bang in it first" using Strings puts s.bang end class Foo SYMBOLS = %I{ foo bar } def bar(one: "First argument", two: "") puts two + " " + one puts SYMBOLS.map( &:to_s ).join( ' ' ) puts __dir__ end end foo = Foo.new foo.bar foo.bar( two: "Second argument" ) Bar = Struct.new( :bar, :foo ) do # nothing end bar = Bar.new("FOO", "BAR").to_h bar.each { |k,v| print "#{k}=>#{v} " } puts module Prepender def bar(one: "1st argument", two: "") puts one + " " + two # the correct order end end class Prepended prepend Prepender def bar(one: "argument 1", two: "argument 2") puts two + " " + one # the incorrect order end end pre = Prepended.new # the method is overridden by the one in Prepender, but arguments are as below pre.bar( two: "2nd argument", one: "1st argument" ) # listed in incorrect order, printed in correct order class Who def whose_there_using_locations caller_locations(1,1).size.times { |t| puts "#{t + 1}. #{ caller_locations(1,1)[t].label }" } end end class There def who who = Who.new who.whose_there_using_locations end end There.new.who # http://blog.marc-andre.ca/2013/02/23/ruby-2-by-example puts "Thanks Marc André from whom most of this was copied ❤" # utf-8
$ brew update $ bundle update $ rails server& Gemfile: source 'https://rubygems.org' More about the complexity of using Apple computers for Rails here: http://rodmclaughlin.com/why-do-rails-developers-use-macs- Back
|