Contenu connexe
Similaire à メタプログラミングRuby輪読会 1-4章(復習), 5.1~5.3章 (20)
メタプログラミングRuby輪読会 1-4章(復習), 5.1~5.3章
- 3. ➤
➤ obj.class # => Greetin
➤
➤ obj.class.instance_methods(false) # => [:welcome]
➤
➤ obj.instance_variables # => [:@text]
3
- 5. ➤ Refinements
➤ module StringExtentions; refine String do; def …
➤
➤ Object#send
obj.send(my_method, 3)
➤ Module#define_method
➤ method_missing
➤ class String; def method_missing(method, *args)…
5
- 8. ➤ Proc
➤
➤ &
➤ lambda
➤ return lambda Proc Proc
➤
➤
➤ Object#method
➤ Object#call
➤ Method#to_proc ⇔ Module#define_method
8
- 14. CLASS_EVAL
➤
➤ Loan to_s
def to_s
# initialize @time = Time.now
“#{@book.upcase} loaned on #{@time}”
end
➤
➤ @time = Loan.time_class.now
➤ def self.time_class
@time_class || Time # @time_class = nil →
end
➤ @time_class FakeTime
Loan.instance_eval { @time_class = FakeTime }
14