Ruby的一些疑问

1、网点看到一断程序,
def m1(a)
puts 'invoke m1'
puts a
end

def self.m1(a)
puts 'invoke self.m1'
a = 20
super
end

m1 10


运行结果如下:
invoke self.m1
invoke m1
20

为何先运行self.m1,这里为何可以使用super?还弄不明白,先记下来。
2、下面的代码在rails源代码中看到的,不明白&:to_s的写法。
(1..10).map(&:to_s)


3、
def who
person = "Matz"
yield("rocks")
# p city #=>undefined local variable or method `city'
end

person = "Matsumoto"

who do |y|
puts("#{person}, #{y} the world") # => Matsumoto, rocks the world
city = "Tokyo"
person = 'new'
end

puts person #=> new

4、#nokogiri css.rb源码
require 'nokogiri/css/xpath_visitor'
x = $-w #<--表示什么意思?
$-w = false
require 'nokogiri/css/parser'
$-w = x

5、
class H < Hash
# Gets or sets keys in the hash.
#
# @cookies.my_favorite = :macadamian
# @cookies.my_favorite
# => :macadamian
#
def method_missing(m,*a)
m.to_s=~/=$/?self[$`]=a[0]:a==[]?self[m.to_s]:super
end
undef id, type if ?? == 63 #这里的??与63表示什么意思?
end
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值