Changeset 6294

Show
Ignore:
Timestamp:
02/06/08 20:14:40 (5 years ago)
Author:
akio0911
Message:

coderepos/dan/ruby/ add some lines

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • dan/ruby/akio0911/rails.rb

    r6236 r6294  
    4848=end 
    4949 
    50  
    51  
    52  
    53  
    54  
     50=begin 
     51p 'name' 
     52p :name 
     53=end 
     54 
     55=begin 
     56p "name".object_id == "name".object_id 
     57p :name.object_id == :name.object_id 
     58=end 
     59 
     60=begin 
     61p "name".class 
     62p "name".intern.class 
     63p :name.object_id == "name".object_id 
     64p :name.object_id == "name".intern.object_id 
     65=end 
     66 
     67=begin 
     68p [1, 2, 3] 
     69p [:num, 10] 
     70=end 
     71 
     72=begin 
     73p %w(a b c) 
     74=end 
     75 
     76=begin 
     77array = [1, 2, 3, 4] 
     78p array.size # 4 
     79p array[0] # 1 
     80p array[1,3] # [2, 3, 4] 
     81p array[4] # nil 
     82p array[-1] # 4 
     83p array[0..2] # [1, 2, 3] 
     84 
     85p [3,1,2].sort # [1, 2, 3] 
     86p %w( a b c ).join(',') # "a,b,c" 
     87 
     88array = [1,2,3,2] 
     89array.uniq! 
     90p array # [1, 2, 3] 
     91 
     92[1,2].each{ |i| puts i } 
     93p [1,2].map{ |i| i*10 } # [10, 20] 
     94p [1,2].push(:a) # [1, 2, :a] 
     95=end 
     96 
     97=begin 
     98valids = { 0 => '無効', 1 => '有効' } 
     99hosts = { 
     100  "localhost" => "127.0.0.1", 
     101  "router" => "192.168.0.1", 
     102} 
     103 
     104p hosts["router"] # "192.168.0.1" 
     105hosts["router"] = nil 
     106p hosts["router"] # nil 
     107=end 
     108 
     109=begin 
     110options = { 
     111  :root => 1, 
     112  :elements => ['a', 'b', 'c'], 
     113  "status" => "OK", 
     114  200 => :ok, 
     115} 
     116=end 
     117 
     118=begin 
     119hash = { :a=>1, :b=>2} 
     120p hash.size # 2 
     121p hash[0] # nil 
     122p hash['a'] # nil 
     123p hash[:a] # 1 
     124p hash.keys # [:a, :b] 
     125p hash.values # [1, 2] 
     126 
     127hash.each_pair do |key, val| 
     128  puts "key=#{key}, val=#{val}" 
     129end 
     130# key=a, val=1 
     131# key=b, val=2 
     132=end 
     133 
     134=begin 
     135flag = 0 
     136if flag 
     137  puts "execute" 
     138end 
     139=end 
     140 
     141=begin 
     142print "処理を開始します" if verbose? 
     143 
     144if verbose? 
     145  print "処理を開始します" 
     146end 
     147=end 
     148 
     149=begin 
     150def hello1 
     151  "hello!" 
     152end 
     153 
     154def hello2 
     155  return "hello!" 
     156end 
     157 
     158p hello1() # "hello!" 
     159p hello2() # "hello!" 
     160=end 
     161 
     162=begin 
     163def hello(name) 
     164  puts "こんにちは、#{name}さん" 
     165end 
     166 
     167hello("ruby") # こんにちは、rubyさん 
     168hello "ruby" # こんにちは、rubyさん 
     169=end 
     170 
     171=begin 
     172def hello 
     173  "メソッドからこんにちは" 
     174end 
     175 
     176hello = "変数でハロー" 
     177p hello 
     178=end 
     179 
     180=begin 
     181def hello 
     182  "メソッドからこんにちは" 
     183end 
     184 
     185hello = "変数でハロー" 
     186puts hello 
     187puts hello() 
     188=end 
     189 
     190=begin 
     191link_to "詳細", :action=>"show", :id=>8 
     192link_to("詳細", :action=>"show", :id=>8) 
     193link_to("詳細", {:action=>"show", :id=>8}) 
     194 
     195options = { 
     196:action => "show", 
     197:id => 8 
     198} 
     199link_to("詳細", options) 
     200 
     201foo("test", :name=>"ruby", 1) # SyntaxError 
     202 
     203link_to "詳細", {:action=>"show", :id=>8}, :title=>"click" 
     204=end 
     205 
     206=begin 
     207p 1 + 1 # 2 
     208block = Proc.new{ 1 + 1 } 
     209p block.call # 2 
     210=end 
     211 
     212=begin 
     213def foo 
     214  yield 
     215end 
     216 
     217#p foo{ 1+1} 2 
     218#foo # LocalJumpError 
     219=end 
     220 
     221=begin 
     222def foo (&block) 
     223  block.call 
     224end 
     225 
     226foo {  p :ok } 
     227=end 
     228 
     229=begin 
     230sum = Proc.new{ |a,b| a+b } 
     231p sum.call(1,2) # 3 
     232=end 
     233 
     234=begin 
     235[1,2,3].each{ |i| p i } 
     236p [1,2,3].map{ |i| i.to_s } # ["1", "2", "3"] 
     237p (1..10).select{ |i| i%2 == 0 } # [2, 4, 6, 8, 10] 
     238=end 
     239 
     240=begin 
     241class Array 
     242  def each 
     243    size.times {|i| yield(self[i])} 
     244  end 
     245 
     246  def collect 
     247    converted = [] 
     248    each { |e| converted << yield(e) } 
     249    return converted 
     250  end 
     251 
     252  def select 
     253    selected = [] 
     254    each { |e| selected << e if yield(e)} 
     255    return selected 
     256  end 
     257end 
     258=end 
    55259 
    56260=begin 
     
    66270=end 
    67271 
     272=begin 
     273module Foo 
     274  class Bar 
     275  end 
     276end 
     277=end 
     278 
     279=begin 
     280p $LOAD_PATH 
     281$LOAD_PATH << "lib" 
     282p $LOAD_PATH 
     283$LOAD_PATH.unshift "lib" 
     284p $LOAD_PATH 
     285=end 
     286 
     287=begin 
     288require 'rubygems' 
     289require 'active_support' 
     290$: << 'lib' 
     291#bar = Foo::Bar.new 
     292=end 
     293 
     294=begin 
     295require 'rubygems' 
     296require 'active_support' 
     297p "Rails".underscore # "rails" 
     298p "ActiveRecord".underscore # "active_record" 
     299p "Active1Record".underscore # "active1_record" 
     300p "Active1record".underscore # "active1record" 
     301p "ToDoList".underscore # "to_do_list" 
     302p "XML".underscore # "xml" 
     303p "XML2".underscore # "xml2" 
     304p "XMLdata".underscore # "xm_ldata" 
     305p "XMLData".underscore # "xml_data" 
     306p "XML2Data".underscore # "xml2_data" 
     307p "Iso2022jpMailer".underscore # "iso2022jp_mailer" 
     308=end 
     309 
     310=begin 
     311require 'rubygems' 
     312require 'active_support' 
     313p "Admin::SuperUser".underscore # "admin/super_user" 
     314p "admin/super_user".classify # "Admin::SuperUser" 
     315=end