lib/mtrack/core.rb in mtrack-0.0.3 vs lib/mtrack/core.rb in mtrack-0.0.4
- old
+ new
@@ -11,13 +11,11 @@
##
# call-seq:
# tracked_methods(group_name = nil) => set
#
- # Returns a set containing the currently tracked methods. An optional
- # +group_name+ parameter can be passed to get the tracked methods of groups
- # othen than the default +nil+ group.
+ # Returns a set containing the currently tracked methods for a +group_name+.
#
# class C
# track_methods :my_group do
# def method_1; end
# def method_2; end
@@ -72,8 +70,29 @@
# homonymous methods tracked in super-states from being displayed as
# #tracked_methods.
def method_undefined(name)
@__mtrack__.delete_tracked name
@__mtrack__.add_undefined name
+ end
+
+ ##
+ # call-seq:
+ # track_methods_with_block(group_name) {|| ... } => set
+ #
+ # All the methods defined within the block will be tracked under the
+ # +group_name+ parameter.
+ #
+ # Returns a set containing the methods that were defined within the block.
+ def track_methods_with_block(group_name, &b)
+ old_methods = public_instance_methods(false)
+
+ begin
+ module_eval(&b)
+ ensure
+ tracked = (public_instance_methods(false) - old_methods).map(&:to_sym).to_set
+ @__mtrack__[group_name].merge_tracked tracked unless tracked.empty?
+ end
+
+ tracked
end
end
end