Ò׽ؽØÍ¼Èí¼þ¡¢µ¥Îļþ¡¢Ãâ°²×°¡¢´¿ÂÌÉ«¡¢½ö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


Ïà¹ØÎĵµ£º

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

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

×Ô¶¯»¯²âÊÔ֮·£¨Èý£© rubyÀïµÄgetÓëset·½·¨

ÕÕÀý¿ÉÒÔÏÈ¿´¶Ë³ÌÐò
class Person
 
  def initialize( name,age=18 )
    @name = name
    @age = age
    @motherland = "China"
  end
 
  def talk
    puts "my name is "+@name+", age is "+@age.to_s
 &n ......

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 ......

Rubyѧϰ±Ê¼ÇÒ»——ÓïÑÔ»ù´¡


#Ò»¡¢ÕâÀïÊÇ×¢ÊÍ£¬Êǵ¥ÐÐ×¢ÊÍ£¬ÀàËÆÓÚ//
puts 3/5#ÕâÀïÊÇÕûÊýÐÎʽµÄ½á¹û
puts 3/5.0#ÕâÀïÊÇСÊýÐÎʽµÄ½á¹û
=begin
  ÕâÊǶàÐÐ×¢ÊÍ£¬Êµ¼ÊÉÏÕâÒ²ÊÇRubyÄÚǶÎĵµ¸ñʽ£¬ÀàËÆÓÚJava doc
  =end²»µ«ÒªÓÐÆðÖ¹£¬»¹ÒªËõ½ø²ÅÓÐÓá£
=end
#¶þ¡¢Á¬ÐÐ
puts "Hello Ruby!"; puts "This is a "\
"String";# ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØÍ¼ | ¸ÓICP±¸09004571ºÅ