diff options
author | Xavier Noria <fxn@hashref.com> | 2009-06-13 00:31:37 +0200 |
---|---|---|
committer | Xavier Noria <fxn@hashref.com> | 2009-06-13 01:10:22 +0200 |
commit | e20e0c8c4260e3718a77367f1b3d7546305defaa (patch) | |
tree | 5c293bd5ddf3ce28eadb96180c0be872797761b2 /railties | |
parent | b9ac9474db13f862a4c43e54cd5672e07a5429db (diff) | |
download | rails-e20e0c8c4260e3718a77367f1b3d7546305defaa.tar.gz rails-e20e0c8c4260e3718a77367f1b3d7546305defaa.tar.bz2 rails-e20e0c8c4260e3718a77367f1b3d7546305defaa.zip |
AS guides: explains Object#metaclass and Object#class_eval
Diffstat (limited to 'railties')
-rw-r--r-- | railties/guides/source/active_support_overview.textile | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/railties/guides/source/active_support_overview.textile b/railties/guides/source/active_support_overview.textile index 80dfd72808..ab9390883b 100644 --- a/railties/guides/source/active_support_overview.textile +++ b/railties/guides/source/active_support_overview.textile @@ -51,6 +51,33 @@ The method +present?+ is equivalent to +!blank?+: assert @response.body.present? # same as !@response.body.blank? </ruby> +h4. +metaclass+ + +The method +metaclass+ returns the singleton class on any object: + +<ruby> +String.metaclass # => #<Class:String> +</ruby> + +h4. +class_eval(*args, &block)+ + +You can evaluate code in the context of any object's singleton class using +class_eval+: + +<ruby> +class Proc + def bind(object) + block, time = self, Time.now + object.class_eval do + method_name = "__bind_#{time.to_i}_#{time.usec}" + define_method(method_name, &block) + method = instance_method(method_name) + remove_method(method_name) + method + end.bind(object) + end +end +</ruby> + h3. Extensions to +Module+ ... |