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

RubyµÄself

selfÉÏÏÂÎÄ
     RubyµÄselfÓкÍJavaµÄthisÏàËÆÖ®´¦£¬µ«ÓÖ´ó²»Ïàͬ¡£JavaµÄ·½·¨¶¼ÊÇÔÚʵÀý·½·¨ÖÐÒýÓã¬ËùÒÔthisÒ»°ã¶¼ÊÇÖ¸Ïòµ±Ç°¶ÔÏóµÄ¡£¶øRubyµÄ´úÂëÖðÐÐÖ´ÐУ¬ËùÒÔÔÚ²»Í¬µÄÉÏÏÂÎÄ(context)self¾ÍÓÐÁ˲»Í¬µÄº¬Ò壬ÏÈÀ´¿´¿´³£¼ûµÄcontext self¶¼´ú±íÄÄЩ
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# Õâ¸öλÖÃλÓÚtop level context£¬´ú±íObjectµÄĬÈ϶ÔÏómain
p self # => main
p self.class # => Object
@self1 = self
# ÒòΪËùÓÐ×Ô¶¨ÒåÀ඼λÓÚmain contextÖ®ÖУ¬ËùÒÔÕâÊÇObjectµÄʵÀý·½·¨
# ͬʱҲ¿ÉÒÔ˵ÊÇÒ»¸öÈ«¾Ö·½·¨
def a_method
@self2 = self
p self
# => main£¬ÒòΪÓÐÁËʵÀý±äÁ¿@self1ºÍ@self2£¬ËùÒÔ´òÓ¡³öÀ´µÄ²»ÊÇmainÕâ¸ö×Ö·û
# => µ«ÈÔÈ»ÊÇmain¶ÔÏó£¬×¢Ê͵ô4£¬8Ðм´¿É¿´µ½Ð§¹û
p @self1 == @self2 # => true
end
# ÏÂÃæÊÇÒ»¸ö¹ØÓÚÀàÖв»Í¬ÉÏÏÂÎĵÄself
class Person
p self # => Person£¬´ú±íµ±Ç°Àà

def instance_method
p self # => #<Person:0xb7818fdc>£¬´ú±íµ±Ç°ÀàµÄʵÀý
end

def self.class_method
p self # => Person£¬ºÍµÚ16ÐÐÒ»Ñù´ú±íµ±Ç°ÀࣨÕâÊÇÀà·½·¨µÄcontext£©£¬ËüÃÇÊÇÏàµÈµÄ
end
end
m = Person.new
def m.hello
p self # => ´ú±ímÕâ¸öµ¥Àý¶ÔÏó
end
m.hello
    ÉÏÃæֻдÁËÔÚÀàÖеÄself£¬ÆäʵÔÚmoduleÒ²ÊÇÒ»ÑùµÄ¡£Í¨¹ýÉÏÃæ´úÂëÄã¿ÉÒÔ·¢ÏÖ£¬selfÒ»Ö±ÒýÓÃ×ÅËüËùÔÚλÖÃÉÏÏÂÎĵÄʵÀý/Àà¡£
    selfÏÔʽ/Òþʽ
    Äã¿ÉÒÔÏÈÊÔ×ÅÔËÐÐÏÂÃæ´úÂ룬¿´¿´ÓÐʲôÒâÍâ·¢ÉúûÓÐ
1
2
3
4
5
6
7
8
9
10
11
12
13
class Person
attr_accessor :name

def set_name(your_name)
name = your_name
end
end
m = Person.new
p m.name
m.set_name('today')
p m.name # => ²ÂÊÇʲô
    Èç¹ûÄã²ÂÊÇtoday¾Í´ó´íÌØ´íÁË£¬´ð°¸ÊÇnil£¬ÎªÊ²Ã´ÊÇnilÄØ£¬ÔÚµÚ5ÐУ¬ÎÒÃ÷Ã÷µ÷ÓõÄÊÇattr_accessorÉú³ÉµÄname=·½·¨¸³ÖµµÄ°¡£¬Äã¿ÉÒÔÔÚÇ°Ãæ¼ÓÉÏselfÊÔÊÔ£¬´úÂëÈçÄãÔ¤ÆÚµÄÒ»ÑùÖ´ÐÐÁË¡£ÔÚÕâÖÖÇé¿öÏÂname = your_name²¢Ã»ÓÐÈ¥µ÷ÓÃattr_accessorÉú³ÉµÄxx=·½·¨£¬¶øÊǽ«nameµ±×÷ÁËÒ»¸ö¾Ö²¿±äÁ¿£¬Èç¹ûÏÔʽµÄÖ¸¶¨self£¬¾ÍûÓÐÎÊÌâÁ


Ïà¹ØÎĵµ£º

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


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

phpRPC + Ruby + Arduino = Ô¶³Ì¿ØÖÆ

phpRPC + Ruby + Arduino = 遠³Ì¿ØÖÆLED開關(?)
àÅ£¬ÎÒÖªµÀ這ÊÇ個ºÜ無ÁĵÄSample :P
關ì¶phpRPC與Arduino請×ÔÐÐGoogle
觀¿´´Ëdemo֮ǰ請ÏÈ°²裝ÁíÍâһƪËùÌáµ½µÄserialport
與ÁíÍâÒ»個Gem
Ì×¼þ£ºphprpc
ÔÚ這個ļ ......

Fix Thrift 0.2.0 Installation with Ruby 1.9.1

When I try the command "gem install thrift" with Ruby 1.9.1, I got a compilation error with something related to a C function "strlcpy()".
Then I searched the web. It seems I am not alone and the community know it.
However I do not want to wait for official update, I want to ......

ruby Á¬½Ó²Ù×÷ sql2005


The following is improved version of the code created by David Mullet, from
http://rubyonwindows.blogspot.com/2007/03/ruby-ado-and-sqlserver.html
require 'win32ole'
class SqlServer
# This class manages database connection and queries
attr_accessor :connection, :data, :fields
attr_wr ......

Ñ¡Ruby»¹ÊÇÑ¡Python

 
  ¡¡×î½ü£¬ÎÒÐèÒªÒ»ÖÖ¿ìËÙ¿ª·¢ÓïÑÔ£¬Ä¿Ç°ÖËÊÖ¿ÉÈȵĿìËÙ¿ª·¢ÓïÑÔ¾ÍÊÇPythonºÍRubyÁË¡£RubyºÍPython¶¼ÊǷdz£ÓÅÐãµÄ½Å±¾ÓïÑÔ£¬ËäÈ»ËûÃǵÄÉè¼ÆÕÜѧ¼¸ºõÍêÈ«²»Í¬£¬µ«ËûÃÇЧÂʲ¶à£¬Ó¦ÓÃÁìÓòÒ²²î¾à²»´ó£¬ËƺõÌìÉú¾ÍÊǾºÕù¶ÔÊÖ¡£µ½µ×Ñ¡ÄǸöÄØ?ÎÒ×öÁËһЩ¼òµ¥µÄ±È½Ï¡£  
   
  ¡¡¡¡ÎÒÃDZȽ ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØͼ | ¸ÓICP±¸09004571ºÅ