1、网点看到一断程序,
运行结果如下:
invoke self.m1
invoke m1
20
为何先运行self.m1,这里为何可以使用super?还弄不明白,先记下来。
2、下面的代码在rails源代码中看到的,不明白&: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
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

被折叠的 条评论
为什么被折叠?



