Ò׽ؽØÍ¼Èí¼þ¡¢µ¥Îļþ¡¢Ãâ°²×°¡¢´¿ÂÌÉ«¡¢½ö160KB

Rubyѧϰ±Ê¼ÇÈý——Àà


#Ò»¡¢¶¨ÒåÒ»¸öÀà
class Person
  def initialize(name,age=18)
    @name=name;
    @age=age;
    @motherland="china";
  end
  def talk
    puts "my name is "+@name+" and I am "+@age.to_s
    if @motherland == "china"
      puts "I am a Chinese."
    else
      puts "I am a foreigner."
    end
  end#talk½áÊø
  attr_writer:motherland 
  attr_writer:age
end#class½áÊø
p1=Person.new("Zhangren",10);
p1.talk;
p1.motherland="abc";
p1.talk;
p1.age=20;
p1.talk;
#¶þ¡¢¼Ì³Ð×ÔÒ»¸öÀà
class Student < Person
  def talk
    #super;#Õâ»áµ÷Óø¸ÀàtalkÖеĴúÂë
    puts "I am a student. my name is "+@name+", age is "+@age.to_s
  end # talk·½·¨½áÊø
end # StudentÀà½áÊø
p3=Student.new("kaichuan",25); p3.talk
p4=Student.new("Ben"); p4.talk
#RubyûÓÐÖØÔØ·½·¨£¬ÒòΪ²ÎÊýûÓÐÀàÐÍ£¬ËùÒÔû·¨ÖØÔØ¡£Óжà̬£¬²»¹ý²»Ì«Ã÷ÏÔ£¬ÒòΪ±äÁ¿¶¼Ã»ÓÐÀàÐÍ£¬ËùÒÔ̸²»Éϸ¸ÀàÒýÓÃÖ¸Ïò×ÓÀà¶ÔÏ󣬶¼ÊÇͳһµÄÒýÓá£
#Èý¡¢±äÁ¿¶¯Ì¬ÐÔ
# E5.3-1.rb
a=5
b="hh"
puts "a = #{a} #{b} #{a}"
puts "b = #{b}"
#ËÄ¡¢ÖØÐ´
def talk (a,b=1)
puts "This is talk version 2."
end
def talk (a)
puts "This is talk version 1."
end
talk (2) # This is talk version 1.
#talk (2,7) # ±¨´í£¬ÒòÎªÖØÐ´Ö®ºó£¬Ö»ÓкóÒ»¸öÓÐÓã¬Ã»ÓÐÖØÔØ¡£¸¸×ÓÀàÖÐÒ²ÊÇÖØÐ´¡£
#Îå¡¢RubyµÄ±äÁ¿µÈ±êʶÃû³ÆÇø·Ö̫Сд¡£È«¾Ö±äÁ¿ÓÃ$ÒýÓã¬ÊµÀý±äÁ¿ÓÃ@£¨Ò²¾ÍÊdzÉÔ±±äÁ¿£¬ÒòΪ²»ÐèÒªÉùÃ÷£¬¶¼ÊÇÖ±½ÓÓã©£¬Àà±äÁ¿ÓÃ@@£¨Æäʵ¾ÍÏ൱ÓÚ¾²Ì¬±äÁ¿£©
$a="\n a is a global value"
puts $a
class StudentClass
  @@count=0
  def initialize( name )
    @name = name
    @@count+=1
  end
  def talk
    puts "I am #@name, This class have #@@count students."
  end
end
p1=StudentClass.new("Student 1 ")
p2=StudentClass.new


Ïà¹ØÎĵµ£º

ÏëÕÒÒ»·ÝRuby on railsµÄ¹¤×÷,ÎÒÓ¦¸ÃÖªµÀÄÄЩ֪ʶ?

  ÐÂÄê¸Õ¿ªÊ¼,ÒѾ­ÓÐһЩÉúÃ͵ÄÅóÓÑÒª¿ªÊ¼ÐµÄÖ°³¡ÉúÑÄÁË,
²»ÖªµÀ»á²»»áÓöµ½ÕâÑùµÄÎÊÌâ: ÏëÕÒÒ»·ÝRuby on railsµÄ¹¤×÷,ÎÒÓ¦¸ÃÖªµÀÄÄЩ֪ʶ
?
     »¹ºÃ,ÎÒ²¢²»ÊÇÏëÖ¸µãÄãʲô,Ö»ÊÇÏë°´ÎÒµÄ˼ά·½Ê½Õ¹¿ª,ÈÃÄãÄÜ"ÎÅ"µ½µã¶«Î÷¼´³É.
¹ÅÔÆ:Öª¼ºÖª±Ë£¬°ÙÕ½²»´ù£»²»Öª±Ë¶øÖª¼º£¬Ò»Ê¤Ò»¸º£» ......

rails on ruby exmaples depot

1.install ruby
    download from http://www.ruby-lang.org/en/news/2009/12/07/ruby-1-9-1-p376-is-released/
2.install rails
   ruby gem install rails --include-dependencies
3.install mysql
   download from http://sourceforge.net
   ruby gem install&nb ......

Rails¡¢Ruby¡¢JAVAǰ¾°±È½Ï

        ÔÚÂÛ̳Àï¿´ÁËdaquan198163ËùдµÄ¡¶³õѧRORµÄÒÉ»ó¡·ÕâÆªÎÄÕ£¬robbinÔڻظ´ÖиøÁËÏêϸµÄ½â´ð£¬¿ÉÊÇ¿´Íê½â´ðÖ®ºó£¬ÎÒÒ²²úÉúÁËһЩÒÉ»ó£¬ÔÚ´ËÏëÎÊÎÊ¡£
        ÔÚrobbinËù¸ø³öµÄ½â´ðµ±ÖУ¬¸ü¶àµÄÊDzûÊörailsµÄºÃ´¦£¬È»¶ø´ó¼Ò¶¼ÖªµÀ£¬railsÖ»Ê ......

½»»¥Ê½ Ruby Shell irb

irb ÊÇ´ÓÃüÁîÐÐÔËÐеÄ
irb µÄÃüÁîÐÐÑ¡Ïժ×Ô¡¡Porgramming Ruby µÚ¶þ°æ£©
-f
½ûÖ¹¶ÁÈ¡~/.irbrc¡¡Suppress reading ~/.irbrc.
-m
Êýѧģʽ£¨Ö§³Ö·ÖÊýºÍ¾ØÕ󣩡¡Math mode (fraction and matrix support is available).
-d
ÉèÖÃ#DEBUGΪtrue(ͬruby -dÒ»Ñù)¡¡¡¡Set $DEBUG to true (same as ``ruby -d'').
-r lo ......

Ruby Ò»²½²½°²×°


http://www.gayathri-frenzy.com/technology/ruby-on-rails
I kept thinking for a while on what do I have next in the store
Here we go “Ruby on Rails”
Ruby on Rails, often shortened to Rails or RoR, is an open source web application framework for the Ruby Programming language.Ruby is a ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØÍ¼ | ¸ÓICP±¸09004571ºÅ