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


Ïà¹ØÎĵµ£º

PythonºÍRubyµÄ¶Ô±È£¬¾ÀÕýһЩÎó½â

PythonºÍRubyµÄ¶Ô±È£¬¾ÀÕýһЩÎó½â
ÏÂÃæÊÇÎÒÔÚ¿´Á½Æª¹ØÓÚPythonºÍRuby¶Ô±ÈµÄÎÄÕÂʱ£¬Ëù×÷µÄ¾ÀÕý£¬Ô­ÎĶ¼Êǹ㷺Á÷Ðеģ¬±È½ÏºÃÕÒ¡£
------------------------------------------------------
¡¶rubyºÍpythonµÄ±È½Ï¡·¸üÕýÒ»µãÊÂÇé
1¡¢Îĵµ¡¢¿ªÔ´ÏîÄ¿¡¢¿âÖ§³Ö£¬ÕâЩ¶«Î÷Ruby²»Òª¸úPython±È£¬²»ÊǼ¸¸öÊýÁ¿¼¶µÄÎÊÌ⣬ºÎ±ØÃ²Ë ......

ruby Ï̵߳ÄÐÔÄܲâÊÔ

ÔÚʹÓÃÖÐrubyµÄ¹ý³ÌÖÐÄÑÃâ»áÓöµ½Ìá¸ßÐÔÄܵÄÎÊÌ⣬Óɴ˱ãÏëÆðÁËrubyÏ̡߳£µ«ÊÇÎÒÔÚʹÓÃÖÐÈ´·¢ÏÖrubyµÄÏß³ÌÈ´²»ÄÜÌá¸ßÐÔÄÜ¡£ÎÒдÁËÒÔÏ´úÂ룬×öÁËЩ¼òµ¥²âÊÔ¡£
´úÂë
# -*- coding: GB2312 -*-
require 'date'
# ʹÓÃỊ̈߳¬Ï̵߳Ĵ¦Àí´úÂëÀïûÓÐsleep
def have_thread_no_sleep
p Time.now
thread1 = Thread.new do
......

Éè¼Æģʽ ¹Û²ìÕßģʽʵÏÖÀý×Ó(ruby)

rubyÖÐ×Ô´øʵÏÖ¹Û²ìÕßģʽµÄÀàobserver¡£¿ÉÒÔÀûÓÃËüÀ´ÊµÏÖ¹Û²ìÕßģʽ¡£
´úÂëÀý×Ó£º
# -*- coding: GB2312 -*-
require 'observer'
# ¹Û²ìÕßģʽ(ruby)µÄʹÓÃÀý×Ó
# ±»¹Û²ìÕßP
class PObservable
include Observable
end
# ¹Û²ìÕßA
class AObserver
# update·½·¨ÃûÊDZØÐëµÄÒªÓеÄ
def update(arg)
puts "AO ......

Ruby ÃüÁîÐÐ ³£ÓÃÃüÁî

´ÓÃüÁîÐÐÆô¶¯Ruby½âÊÍÆ÷ʱ£¬Äã²»½ö¿ÉÒÔÌṩ³ÌÐòÎļþµÄÃû×Ö£¬¶øÇÒ¿ÉÒÔÌṩһ¸ö»ò¶à¸öÃüÁîÐпª¹Ø¡£ÄãÑ¡ÔñµÄ¿ª¹Øָʾ½âÊÍÆ÷ÒÔÒ»ÖÖÌض¨µÄ·½Ê½ÔËת£¬²¢ÇÒ/»òÕßÖ´ÐÐÌض¨µÄ²Ù×÷¡£
RubyÃüÁîÐпª¹ØÓÐ20¶à¸ö£¬ÆäÖÐÓÐЩºÜÉÙʹÓã¬ÓÐЩÔòÿÌì±»ºÜ¶àRuby³ÌÐòԱʹÓá£ÔÚÕâÀïÎÒÃǽ«ÔÙ¿´¼¸¸ö×î³£Óõġ££¨ÄãÒѾ­¿´µ½¹ýÆäÖеÄÁ½¸ö£¬-cºÍ&ndas ......

ruby on rails ½â¾ömultiple select ´æ´¢ºÍupdate

²Ù×÷ϵͳubuntu£¬¿ª·¢¹¤¾ßnetbeans
vendorÊý¾Ý¿â±íÓÐ×Ö¶Îservice_category varchar(100)
<% form_for :vendor, @vendor, :url => sellers_path do |f| %>
  <%= f.select(:service_category,
                  ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØͼ | ¸ÓICP±¸09004571ºÅ