Skip to content

Commit

Permalink
Add explanatory note for class_eval
Browse files Browse the repository at this point in the history
  • Loading branch information
amcaplan committed Jan 31, 2016
1 parent 3984161 commit 011c862
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions lib/dynamic_class.rb
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,14 @@ def hash
def add_methods!(key)
self.class.send(:attr_accessor, key)
self.class.attributes << key

# I'm pretty sure this is safe, because attempting to add an attribute
# that isn't a valid instance variable name will raise an error. Please
# contact the maintainer if you find a situation where this could be a
# security problem.
#
# The reason to use class_eval here is because, based on benchmarking,
# this defines the fastest version of #to_h possible.
self.class.class_eval <<-RUBY
def to_h
{
Expand Down

0 comments on commit 011c862

Please sign in to comment.