diff options
| author | luke <luke@980ebf18-57e1-0310-9a29-db15c13687c0> | 2006-08-20 02:28:33 +0000 |
|---|---|---|
| committer | luke <luke@980ebf18-57e1-0310-9a29-db15c13687c0> | 2006-08-20 02:28:33 +0000 |
| commit | b2031aa32995331474244150bbc97f467e3ada7b (patch) | |
| tree | 1d7beabef0b5f34716a11f3c0c2916036fbbcd2a /lib/puppet/util/metaid.rb | |
| parent | beba3e480c7ad7f942414a8aa31f96b5b42b53e4 (diff) | |
| download | puppet-b2031aa32995331474244150bbc97f467e3ada7b.tar.gz puppet-b2031aa32995331474244150bbc97f467e3ada7b.tar.xz puppet-b2031aa32995331474244150bbc97f467e3ada7b.zip | |
Making some of the metaprogramming a bit more explicit and a bit easier to manage. In the process, I have created multiple Util modules, only one of which is used for this current commit.
The main work in this commit is that I created a single, common method for dynamically creating classes and moved all of the Class.new users to using this class. It handles a lot of the complexity for me, and most of the users have just a couple of lines of code, now, instead of tens.
git-svn-id: https://reductivelabs.com/svn/puppet/trunk@1473 980ebf18-57e1-0310-9a29-db15c13687c0
Diffstat (limited to 'lib/puppet/util/metaid.rb')
| -rw-r--r-- | lib/puppet/util/metaid.rb | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/lib/puppet/util/metaid.rb b/lib/puppet/util/metaid.rb new file mode 100644 index 000000000..b2b8a0c43 --- /dev/null +++ b/lib/puppet/util/metaid.rb @@ -0,0 +1,17 @@ +module Puppet::Util::MetaID + # The hidden singleton lurks behind everyone + def metaclass; class << self; self; end; end + def meta_eval &blk; metaclass.instance_eval &blk; end + + # Adds methods to a metaclass + def meta_def name, &blk + meta_eval { define_method name, &blk } + end + + # Defines an instance method within a class + def class_def name, &blk + class_eval { define_method name, &blk } + end +end + +# $Id$ |
