x,y=1,2 #x=[1]; y=2

x,y=1,2,3 #x=[1,2]; y=3

x,y=1 #x=[]; y=1

x,y=1,2 #x=[1]; y=2

x,y=1,2,3 #x=[1,2]; y=3

x,y=1 #x=[]; y=1

x,y,*z=1,*[2,3,4] #x=1;y=2;z=[3,4];#operator puts (0b1011 puts (0b10110 >> 2).to_s(2) #101 puts 11 puts 22>>2 #5message="hello" messages=[] message messages

x,y=1,2 #x=[1]; y=2

x,y=1,2,3 #x=[1,2]; y=3

x,y=1 #x=[]; y=1

x,y,*z=1,*[2,3,4] #x=1;y=2;z=[3,4];#operator puts (0b1011 puts (0b10110 >> 2).to_s(2) #101 puts 11 puts 22>>2 #5message="hello" messages=[] message messages

x,y=1,2 #x=[1]; y=2

x,y=1,2,3 #x=[1,2]; y=3

x,y=1 #x=[]; y=1

x,y,*z=1,*[2,3,4] #x=1;y=2;z=[3,4];#operator puts (0b1011 puts (0b10110 >> 2).to_s(2) #101 puts 11 puts 22>>2 #5

x,y=1,2 #x=[1]; y=2

x,y=1,2,3 #x=[1,2]; y=3

x,y=1 #x=[]; y=1

x,y,*z=1,*[2,3,4] #x=1;y=2;z=[3,4];puts (0b1011 puts (0b10110 >> 2).to_s(2) #101 puts 11 puts 22>>2 #5

x,y=1,2 #x=[1]; y=2

x,y=1,2,3 #x=[1,2]; y=3

x,y=1 #x=[]; y=1

x,y,*z=1,*[2,3,4] #x=1;y=2;z=[3,4];#operator puts (0b1011 puts (0b10110 >> 2).to_s(2) #101 puts 11 puts 22>>2 #5message="hello" messages=[] message messages

x,y=1,2 #x=[1]; y=2

x,y=1,2,3 #x=[1,2]; y=3

Expressions and Operator

#method invocations puts "hello world" #"puts" invoked on self , with one string arg puts Math.sqrt(2) #"sqrt" invoked on object Math with one arg message="hello world" puts message.length #"length" invoked on object message;no args a=[0,1…

Programming Ruby Object

#Object #string t copyed from string s s="Ruby" t=s p t #=>"Ruby" s="Rails" p t #=>"Ruby" p s #=>"Rails" t[-1]="" print s #=>Rails puts "\n" print t #=>Rubo="test" o.class o.class.superclass o.class.superclass.superclass if o.class==String…

Programming Ruby Range

#Range cold_war=1946..1986 birthday_year=1974 if cold_war.include? birthday_year puts "include birthday_year" else puts "not include birthday_year" enda="a".."c" a.each{|l| print "#{l}"} #abc puts "\n" a.step(2){|l| print "#{l}"} #=>ac put…

Programming Ruby Hashes

#hashes numbers=Hash.new numbers["one"]=1 numbers["two"]=2 numbers["three"]=3sum=numbers["one"]+numbers["two"]+numbers["three"] puts summembers={"one"=>1,"two"=>2,"three"=>3} p members members={:one=>1,:two=>2,:three=>3} p membersreturn {"…

Ruby on Rails install

Railsをインストールする前に gem update しておきましょう。 $ gem update rails のインストール $ sudo gem install rails$ rbenv rehashRails がインストールされたかどうか確認してみましょう。$ rails -v Rails 3.2.9、試しにやってみましょう。$ rails…

Programming Ruby Array

#arraywords=%w|({ puts words white=%W(s\s s\t s\r s\n) #same as:["s\s","s\t","s\r","s\n"] puts whiteempty=Array.new #:returns a new empty array nils=Array.new(3) #[nil,nil,nil]:new array with 3 nil elements zeros=Array.new(4,0) #[0,0,0,0]:…

Programming Ruby multibyte String

s="2×2=4" p s.bytesize #=>6 s.bytesize.times{|i| print s.getbyte(i)," "} #=> 50,195,151,50,61,52 puts "\n" p s.length #=>5s.length.times{|i| print s[i], " "} #=>2 × 2 = 4s.setbyte(5,s.getbyte(5)+1) #s is now "2×2=5" s.length.times{|i| prin…

Programming Ruby String

String literal "string" 'string'?\u20AC==?€ concatenate string and >= s='hello' puts s[0] #output 'h' puts s[s.length-1] #output 'o' puts s[-2] #output 'l' puts s[-s.length] #output 'h' puts s[s.length] #nil :there is no character at that …

Programming Ruby

[here document] greeting=> Hello There World

Ruby学習 loop

;while loop you don't know how many times you'll be looping. ;until loop 1 between 10 counter=1 until counter==11 puts counter counter+=1 end;for loop you know how many times you'll be looping. for num in 1..10 puts num end;loop method i=2…