Skip to content

Instantly share code, notes, and snippets.

@jeffmccune
Created August 16, 2012 20:43
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jeffmccune/3373489 to your computer and use it in GitHub Desktop.
Save jeffmccune/3373489 to your computer and use it in GitHub Desktop.
Ruby classes and threads

class_constants.rb

#! /usr/bin/env ruby

t1 = Thread.new do
  sleep(5)
  puts "defining Klass"
  class Klass; end
end

t2 = Thread.new do
  sleep(10)
  puts "undefining Klass"
  Object.class_eval() { remove_const :Klass }
end

t3 = Thread.new do
  begin
    sleep(1)
    k = Klass.new
    puts "#{k} instantiated!"
  rescue Exception => detail
    puts "Klass error: #{detail}"
  end while true
end


t3.join

Produced Output

$ ./constants.rb 
Klass error: uninitialized constant Klass
Klass error: uninitialized constant Klass
Klass error: uninitialized constant Klass
Klass error: uninitialized constant Klass
defining Klass
#<Klass:0x007f8d040917b0> instantiated!
#<Klass:0x007f8d040916e8> instantiated!
#<Klass:0x007f8d04091620> instantiated!
#<Klass:0x007f8d04091558> instantiated!
#<Klass:0x007f8d04091490> instantiated!
undefining Klass
Klass error: uninitialized constant Klass
Klass error: uninitialized constant Klass
Klass error: uninitialized constant Klass
Klass error: uninitialized constant Klass
Klass error: uninitialized constant Klass
^C./constants.rb:27:in `join': Interrupt
        from ./constants.rb:27:in `<main>'

Anonymous Classes

Diff

diff --git a/lib/puppet/util/classgen.rb b/lib/puppet/util/classgen.rb
index 7993e69..8901c7a 100644
--- a/lib/puppet/util/classgen.rb
+++ b/lib/puppet/util/classgen.rb
@@ -142,6 +142,8 @@ module Puppet::Util::ClassGen
 
     if is_constant_defined?(const)
       if options[:overwrite]
+        # JJM This can't possibly work as Puppet.info is not always a method in
+        # this point of the life-cycle.
         Puppet.info "Redefining #{name} in #{self}"
         remove_const(const)
       else
@@ -149,7 +151,11 @@ module Puppet::Util::ClassGen
           "Class #{const} is already defined in #{self}"
       end
     end
+    # We can't use klass.name because Puppet apparently overrides the name
+    # method.  =(  Yay for us.
+    puts "Defining constant: #{const} (Name before): #{klass.ancestors.first}"
     const_set(const, klass)
+    puts "Defining constant: #{const} (Name after ): #{klass.ancestors.first}"
 
     const
   end

Output

Defining constant: DestSyslog (Name before): #<Class:0x007fb19113c730>
Defining constant: DestSyslog (Name after ): Puppet::Util::Log::DestSyslog
Defining constant: DestFile (Name before): #<Class:0x007fb19113bfb0>
Defining constant: DestFile (Name after ): Puppet::Util::Log::DestFile
Defining constant: DestConsole (Name before): #<Class:0x007fb19113b268>
Defining constant: DestConsole (Name after ): Puppet::Util::Log::DestConsole
Defining constant: DestHost (Name before): #<Class:0x007fb19111c660>
Defining constant: DestHost (Name after ): Puppet::Util::Log::DestHost
Defining constant: DestReport (Name before): #<Class:0x007fb19111c070>
Defining constant: DestReport (Name after ): Puppet::Util::Log::DestReport
Defining constant: DestArray (Name before): #<Class:0x007fb19111b2d8>
Defining constant: DestArray (Name after ): Puppet::Util::Log::DestArray
Defining constant: DestEventlog (Name before): #<Class:0x007fb19111a5e0>
Defining constant: DestEventlog (Name after ): Puppet::Util::Log::DestEventlog
Defining constant: MetaParamNoop (Name before): #<Class:0x007fb1911339c8>
Defining constant: MetaParamNoop (Name after ): Puppet::Type::MetaParamNoop
Defining constant: MetaParamSchedule (Name before): #<Class:0x007fb191132640>
Defining constant: MetaParamSchedule (Name after ): Puppet::Type::MetaParamSchedule
Defining constant: MetaParamAudit (Name before): #<Class:0x007fb1911313a8>
Defining constant: MetaParamAudit (Name after ): Puppet::Type::MetaParamAudit
Defining constant: MetaParamCheck (Name before): #<Class:0x007fb191136f10>
Defining constant: MetaParamCheck (Name after ): Puppet::Type::MetaParamCheck
Defining constant: MetaParamLoglevel (Name before): #<Class:0x007fb191136588>
Defining constant: MetaParamLoglevel (Name after ): Puppet::Type::MetaParamLoglevel
Defining constant: MetaParamAlias (Name before): #<Class:0x007fb191135368>
Defining constant: MetaParamAlias (Name after ): Puppet::Type::MetaParamAlias
Defining constant: MetaParamTag (Name before): #<Class:0x007fb191134990>
Defining constant: MetaParamTag (Name after ): Puppet::Type::MetaParamTag
Defining constant: MetaParamRequire (Name before): #<Class:0x007fb19113b920>
Defining constant: MetaParamRequire (Name after ): Puppet::Type::MetaParamRequire
Defining constant: MetaParamSubscribe (Name before): #<Class:0x007fb19113abb0>
Defining constant: MetaParamSubscribe (Name after ): Puppet::Type::MetaParamSubscribe
Defining constant: MetaParamBefore (Name before): #<Class:0x007fb191139eb8>
Defining constant: MetaParamBefore (Name after ): Puppet::Type::MetaParamBefore
Defining constant: MetaParamNotify (Name before): #<Class:0x007fb191139210>
Defining constant: MetaParamNotify (Name after ): Puppet::Type::MetaParamNotify
Defining constant: MetaParamStage (Name before): #<Class:0x007fb191140038>
Defining constant: MetaParamStage (Name after ): Puppet::Type::MetaParamStage
Defining constant: Component (Name before): Puppet::Type::Component
Defining constant: Component (Name after ): Puppet::Type::Component
Defining constant: ParameterName (Name before): #<Class:0x007fb193a7d428>
Defining constant: ParameterName (Name after ): Puppet::Type::Component::ParameterName
Defining constant: Log (Name before): #<Class:0x007fb19401d400>
Defining constant: Log (Name after ): Puppet::Util::Instrumentation::Log
Defining constant: Performance (Name before): #<Class:0x007fb19403d598>
Defining constant: Performance (Name after ): Puppet::Util::Instrumentation::Performance
Defining constant: Stage (Name before): Puppet::Type::Stage
Defining constant: Stage (Name after ): Puppet::Type::Stage
Defining constant: ParameterName (Name before): #<Class:0x007fb190835588>
Defining constant: ParameterName (Name after ): Puppet::Type::Stage::ParameterName
Defining constant: Notify (Name before): Puppet::Type::Notify
Defining constant: Notify (Name after ): Puppet::Type::Notify
Defining constant: Message (Name before): #<Class:0x007fb193929838>
Defining constant: Message (Name after ): Puppet::Type::Notify::Message
Defining constant: ParameterWithpath (Name before): #<Class:0x007fb1939285f0>
Defining constant: ParameterWithpath (Name after ): Puppet::Type::Notify::ParameterWithpath
Defining constant: ParameterName (Name before): #<Class:0x007fb193927768>
Defining constant: ParameterName (Name after ): Puppet::Type::Notify::ParameterName
Defining constant: Schedule (Name before): Puppet::Type::Schedule
Defining constant: Schedule (Name after ): Puppet::Type::Schedule
Defining constant: ParameterName (Name before): #<Class:0x007fb1940be648>
Defining constant: ParameterName (Name after ): Puppet::Type::Schedule::ParameterName
Defining constant: ParameterRange (Name before): #<Class:0x007fb1940bd6a8>
Defining constant: ParameterRange (Name after ): Puppet::Type::Schedule::ParameterRange
Defining constant: ParameterPeriodmatch (Name before): #<Class:0x007fb1940bbb78>
Defining constant: ParameterPeriodmatch (Name after ): Puppet::Type::Schedule::ParameterPeriodmatch
Defining constant: ParameterPeriod (Name before): #<Class:0x007fb1940b65b0>
Defining constant: ParameterPeriod (Name after ): Puppet::Type::Schedule::ParameterPeriod
Defining constant: ParameterRepeat (Name before): #<Class:0x007fb1940b55c0>
Defining constant: ParameterRepeat (Name after ): Puppet::Type::Schedule::ParameterRepeat
Defining constant: ParameterWeekday (Name before): #<Class:0x007fb1940b49e0>
Defining constant: ParameterWeekday (Name after ): Puppet::Type::Schedule::ParameterWeekday
Defining constant: Filebucket (Name before): Puppet::Type::Filebucket
Defining constant: Filebucket (Name after ): Puppet::Type::Filebucket
Defining constant: ParameterName (Name before): #<Class:0x007fb1940305c8>
Defining constant: ParameterName (Name after ): Puppet::Type::Filebucket::ParameterName
Defining constant: ParameterServer (Name before): #<Class:0x007fb19402fcb8>
Defining constant: ParameterServer (Name after ): Puppet::Type::Filebucket::ParameterServer
Defining constant: ParameterPort (Name before): #<Class:0x007fb19402f358>
Defining constant: ParameterPort (Name after ): Puppet::Type::Filebucket::ParameterPort
Defining constant: ParameterPath (Name before): #<Class:0x007fb19402dfd0>
Defining constant: ParameterPath (Name after ): Puppet::Type::Filebucket::ParameterPath
Defining constant: File (Name before): Puppet::Type::File
Defining constant: File (Name after ): Puppet::Type::File
Defining constant: ParameterPath (Name before): #<Class:0x007fb19201c700>
Defining constant: ParameterPath (Name after ): Puppet::Type::File::ParameterPath
Defining constant: ParameterBackup (Name before): #<Class:0x007fb192022a88>
Defining constant: ParameterBackup (Name after ): Puppet::Type::File::ParameterBackup
Defining constant: ParameterRecurse (Name before): #<Class:0x007fb1920212a0>
Defining constant: ParameterRecurse (Name after ): Puppet::Type::File::ParameterRecurse
Defining constant: ParameterRecurselimit (Name before): #<Class:0x007fb19201fd88>
Defining constant: ParameterRecurselimit (Name after ): Puppet::Type::File::ParameterRecurselimit
Defining constant: ParameterReplace (Name before): #<Class:0x007fb192026548>
Defining constant: ParameterReplace (Name after ): Puppet::Type::File::ParameterReplace
Defining constant: ParameterForce (Name before): #<Class:0x007fb192024dd8>
Defining constant: ParameterForce (Name after ): Puppet::Type::File::ParameterForce
Defining constant: ParameterIgnore (Name before): #<Class:0x007fb192023988>
Defining constant: ParameterIgnore (Name after ): Puppet::Type::File::ParameterIgnore
Defining constant: ParameterLinks (Name before): #<Class:0x007fb19202a2b0>
Defining constant: ParameterLinks (Name after ): Puppet::Type::File::ParameterLinks
Defining constant: ParameterPurge (Name before): #<Class:0x007fb192028a28>
Defining constant: ParameterPurge (Name after ): Puppet::Type::File::ParameterPurge
Defining constant: ParameterSourceselect (Name before): #<Class:0x007fb192033338>
Defining constant: ParameterSourceselect (Name after ): Puppet::Type::File::ParameterSourceselect
Defining constant: ParameterProvider (Name before): #<Class:0x007fb1920cca10>
Defining constant: ParameterProvider (Name after ): Puppet::Type::File::ParameterProvider
Defining constant: ProviderPosix (Name before): #<Class:0x007fb1920d54a8>
Defining constant: ProviderPosix (Name after ): Puppet::Type::File::ProviderPosix
Defining constant: ProviderWindows (Name before): #<Class:0x007fb194021820>
Defining constant: ProviderWindows (Name after ): Puppet::Type::File::ProviderWindows
Defining constant: ParameterChecksum (Name before): #<Class:0x007fb1940453d8>
Defining constant: ParameterChecksum (Name after ): Puppet::Type::File::ParameterChecksum
Defining constant: Content (Name before): #<Class:0x007fb193856690>
Defining constant: Content (Name after ): Puppet::Type::File::Content
Defining constant: ParameterSource (Name before): #<Class:0x007fb193a0e6e0>
Defining constant: ParameterSource (Name after ): Puppet::Type::File::ParameterSource
Defining constant: Target (Name before): #<Class:0x007fb193a46798>
Defining constant: Target (Name after ): Puppet::Type::File::Target
Defining constant: Ensure (Name before): #<Class:0x007fb193a95eb0>
Defining constant: Ensure (Name after ): Puppet::Type::File::Ensure
Defining constant: Owner (Name before): #<Class:0x007fb193aa80b0>
Defining constant: Owner (Name after ): Puppet::Type::File::Owner
Defining constant: Group (Name before): #<Class:0x007fb193ab03a0>
Defining constant: Group (Name after ): Puppet::Type::File::Group
Defining constant: Mode (Name before): #<Class:0x007fb193ac4418>
Defining constant: Mode (Name after ): Puppet::Type::File::Mode
Defining constant: Type (Name before): #<Class:0x007fb193ac5e30>
Defining constant: Type (Name after ): Puppet::Type::File::Type
Defining constant: ParameterSelinux_ignore_defaults (Name before): #<Class:0x007fb193adec28>
Defining constant: ParameterSelinux_ignore_defaults (Name after ): Puppet::Type::File::ParameterSelinux_ignore_defaults
Defining constant: Seluser (Name before): #<Class:0x007fb1923d49b0>
Defining constant: Seluser (Name after ): Puppet::Type::File::Seluser
Defining constant: Selrole (Name before): #<Class:0x007fb1923d4280>
Defining constant: Selrole (Name after ): Puppet::Type::File::Selrole
Defining constant: Seltype (Name before): #<Class:0x007fb1923d3b50>
Defining constant: Seltype (Name after ): Puppet::Type::File::Seltype
Defining constant: Selrange (Name before): #<Class:0x007fb1923d3420>
Defining constant: Selrange (Name after ): Puppet::Type::File::Selrange
Defining constant: Ctime (Name before): #<Class:0x007fb1923d11e8>
Defining constant: Ctime (Name after ): Puppet::Type::File::Ctime
Defining constant: Mtime (Name before): #<Class:0x007fb1923e20b0>
Defining constant: Mtime (Name after ): Puppet::Type::File::Mtime
Defining constant: User (Name before): Puppet::Type::User
Defining constant: User (Name after ): Puppet::Type::User
Defining constant: Ensure (Name before): #<Class:0x007fb192453e90>
Defining constant: Ensure (Name after ): Puppet::Type::User::Ensure
Defining constant: Home (Name before): #<Class:0x007fb192453170>
Defining constant: Home (Name after ): Puppet::Type::User::Home
Defining constant: Uid (Name before): #<Class:0x007fb192452ab8>
Defining constant: Uid (Name after ): Puppet::Type::User::Uid
Defining constant: Gid (Name before): #<Class:0x007fb192452388>
Defining constant: Gid (Name after ): Puppet::Type::User::Gid
Defining constant: Comment (Name before): #<Class:0x007fb192451c58>
Defining constant: Comment (Name after ): Puppet::Type::User::Comment
Defining constant: Shell (Name before): #<Class:0x007fb1924515c8>
Defining constant: Shell (Name after ): Puppet::Type::User::Shell
Defining constant: Password (Name before): #<Class:0x007fb193a0ea50>
Defining constant: Password (Name after ): Puppet::Type::User::Password
Defining constant: Password_min_age (Name before): #<Class:0x007fb193a0cc00>
Defining constant: Password_min_age (Name after ): Puppet::Type::User::Password_min_age
Defining constant: Password_max_age (Name before): #<Class:0x007fb19245d738>
Defining constant: Password_max_age (Name after ): Puppet::Type::User::Password_max_age
Defining constant: Groups (Name before): #<Class:0x007fb19245ce28>
Defining constant: Groups (Name after ): Puppet::Type::User::Groups
Defining constant: ParameterName (Name before): #<Class:0x007fb19245c680>
Defining constant: ParameterName (Name after ): Puppet::Type::User::ParameterName
Defining constant: ParameterMembership (Name before): #<Class:0x007fb19245bfa0>
Defining constant: ParameterMembership (Name after ): Puppet::Type::User::ParameterMembership
Defining constant: ParameterSystem (Name before): #<Class:0x007fb19245b6e0>
Defining constant: ParameterSystem (Name after ): Puppet::Type::User::ParameterSystem
Defining constant: ParameterAllowdupe (Name before): #<Class:0x007fb19245ad08>
Defining constant: ParameterAllowdupe (Name after ): Puppet::Type::User::ParameterAllowdupe
Defining constant: ParameterManagehome (Name before): #<Class:0x007fb19245a330>
Defining constant: ParameterManagehome (Name after ): Puppet::Type::User::ParameterManagehome
Defining constant: Expiry (Name before): #<Class:0x007fb193a02bb0>
Defining constant: Expiry (Name after ): Puppet::Type::User::Expiry
Defining constant: Roles (Name before): #<Class:0x007fb192461b58>
Defining constant: Roles (Name after ): Puppet::Type::User::Roles
Defining constant: ParameterRole_membership (Name before): #<Class:0x007fb1924611f8>
Defining constant: ParameterRole_membership (Name after ): Puppet::Type::User::ParameterRole_membership
Defining constant: Auths (Name before): #<Class:0x007fb1924609b0>
Defining constant: Auths (Name after ): Puppet::Type::User::Auths
Defining constant: ParameterAuth_membership (Name before): #<Class:0x007fb192460078>
Defining constant: ParameterAuth_membership (Name after ): Puppet::Type::User::ParameterAuth_membership
Defining constant: Profiles (Name before): #<Class:0x007fb19245f830>
Defining constant: Profiles (Name after ): Puppet::Type::User::Profiles
Defining constant: ParameterProfile_membership (Name before): #<Class:0x007fb19245eef8>
Defining constant: ParameterProfile_membership (Name after ): Puppet::Type::User::ParameterProfile_membership
Defining constant: Keys (Name before): #<Class:0x007fb19245e6b0>
Defining constant: Keys (Name after ): Puppet::Type::User::Keys
Defining constant: ParameterKey_membership (Name before): #<Class:0x007fb1939f3a98>
Defining constant: ParameterKey_membership (Name after ): Puppet::Type::User::ParameterKey_membership
Defining constant: Project (Name before): #<Class:0x007fb192465e88>
Defining constant: Project (Name after ): Puppet::Type::User::Project
Defining constant: ParameterIa_load_module (Name before): #<Class:0x007fb1924655c8>
Defining constant: ParameterIa_load_module (Name after ): Puppet::Type::User::ParameterIa_load_module
Defining constant: Attributes (Name before): #<Class:0x007fb192464e48>
Defining constant: Attributes (Name after ): Puppet::Type::User::Attributes
Defining constant: ParameterAttribute_membership (Name before): #<Class:0x007fb192464510>
Defining constant: ParameterAttribute_membership (Name after ): Puppet::Type::User::ParameterAttribute_membership
Defining constant: ParameterProvider (Name before): #<Class:0x007fb192310ee8>
Defining constant: ParameterProvider (Name after ): Puppet::Type::User::ParameterProvider
Defining constant: ProviderAix (Name before): #<Class:0x007fb19230f930>
Defining constant: ProviderAix (Name after ): Puppet::Type::User::ProviderAix
Defining constant: ProviderDirectoryservice (Name before): #<Class:0x007fb192019640>
Defining constant: ProviderDirectoryservice (Name after ): Puppet::Type::User::ProviderDirectoryservice
Defining constant: ProviderUseradd (Name before): #<Class:0x007fb1920b2b88>
Defining constant: ProviderUseradd (Name after ): Puppet::Type::User::ProviderUseradd
Defining constant: ProviderHpuxuseradd (Name before): #<Class:0x007fb1920da480>
Defining constant: ProviderHpuxuseradd (Name after ): Puppet::Type::User::ProviderHpuxuseradd
Defining constant: ProviderLdap (Name before): #<Class:0x007fb194097d18>
Defining constant: ProviderLdap (Name after ): Puppet::Type::User::ProviderLdap
Defining constant: ProviderPw (Name before): #<Class:0x007fb19393a3e0>
Defining constant: ProviderPw (Name after ): Puppet::Type::User::ProviderPw
Defining constant: ProviderUser_role_add (Name before): #<Class:0x007fb193a68a78>
Defining constant: ProviderUser_role_add (Name after ): Puppet::Type::User::ProviderUser_role_add
Defining constant: ProviderWindows_adsi (Name before): #<Class:0x007fb1923b1348>
Defining constant: ProviderWindows_adsi (Name after ): Puppet::Type::User::ProviderWindows_adsi
Defining constant: Group (Name before): Puppet::Type::Group
Defining constant: Group (Name after ): Puppet::Type::Group
Defining constant: Ensure (Name before): #<Class:0x007fb1923e6c78>
Defining constant: Ensure (Name after ): Puppet::Type::Group::Ensure
Defining constant: Gid (Name before): #<Class:0x007fb1923e62a0>
Defining constant: Gid (Name after ): Puppet::Type::Group::Gid
Defining constant: Members (Name before): #<Class:0x007fb1923e5b98>
Defining constant: Members (Name after ): Puppet::Type::Group::Members
Defining constant: ParameterAuth_membership (Name before): #<Class:0x007fb1923e5210>
Defining constant: ParameterAuth_membership (Name after ): Puppet::Type::Group::ParameterAuth_membership
Defining constant: ParameterName (Name before): #<Class:0x007fb1923ee220>
Defining constant: ParameterName (Name after ): Puppet::Type::Group::ParameterName
Defining constant: ParameterAllowdupe (Name before): #<Class:0x007fb1923edb40>
Defining constant: ParameterAllowdupe (Name after ): Puppet::Type::Group::ParameterAllowdupe
Defining constant: ParameterIa_load_module (Name before): #<Class:0x007fb1923ed190>
Defining constant: ParameterIa_load_module (Name after ): Puppet::Type::Group::ParameterIa_load_module
Defining constant: Attributes (Name before): #<Class:0x007fb1923ec9e8>
Defining constant: Attributes (Name after ): Puppet::Type::Group::Attributes
Defining constant: ParameterAttribute_membership (Name before): #<Class:0x007fb1923ec060>
Defining constant: ParameterAttribute_membership (Name after ): Puppet::Type::Group::ParameterAttribute_membership
Defining constant: ParameterSystem (Name before): #<Class:0x007fb1923eb7a0>
Defining constant: ParameterSystem (Name after ): Puppet::Type::Group::ParameterSystem
Defining constant: ParameterProvider (Name before): #<Class:0x007fb192409bb0>
Defining constant: ParameterProvider (Name after ): Puppet::Type::Group::ParameterProvider
Defining constant: ProviderAix (Name before): #<Class:0x007fb1924088c8>
Defining constant: ProviderAix (Name after ): Puppet::Type::Group::ProviderAix
Defining constant: ProviderDirectoryservice (Name before): #<Class:0x007fb19237a7d0>
Defining constant: ProviderDirectoryservice (Name after ): Puppet::Type::Group::ProviderDirectoryservice
Defining constant: ProviderGroupadd (Name before): #<Class:0x007fb192364fe8>
Defining constant: ProviderGroupadd (Name after ): Puppet::Type::Group::ProviderGroupadd
Defining constant: ProviderLdap (Name before): #<Class:0x007fb1923606a0>
Defining constant: ProviderLdap (Name after ): Puppet::Type::Group::ProviderLdap
Defining constant: ProviderPw (Name before): #<Class:0x007fb192427110>
Defining constant: ProviderPw (Name after ): Puppet::Type::Group::ProviderPw
Defining constant: ProviderWindows_adsi (Name before): #<Class:0x007fb192451aa0>
Defining constant: ProviderWindows_adsi (Name after ): Puppet::Type::Group::ProviderWindows_adsi
Defining constant: Whit (Name before): Puppet::Type::Whit
Defining constant: Whit (Name after ): Puppet::Type::Whit
Defining constant: ParameterName (Name before): #<Class:0x007fb1923089c8>
Defining constant: ParameterName (Name after ): Puppet::Type::Whit::ParameterName
hello
/Stage[main]//Notify[hello]/message: defined 'message' as 'hello'
Finished catalog run in 0.02 seconds
Defining constant: Store (Name before): #<Module:0x007fb192337ea8>
Defining constant: Store (Name after ): Puppet::Reports::Store
@jeffmccune
Copy link
Author

A bit more information.

Ruby support anonymous classes using Class.new but as soon as you bind an anonymous class to a constant the class takes on name of that constant. See Ruby - Creating Anonymous Classes

In Puppet, we have the plumbing to create anonymous classes through genclass and genthing, however we quickly bind them to contants which means they're not anonymous for long at all and means they cannot be thread-local.

diff --git a/lib/puppet/util/classgen.rb b/lib/puppet/util/classgen.rb
index 7993e69..a6dddb0 100644
--- a/lib/puppet/util/classgen.rb
+++ b/lib/puppet/util/classgen.rb
@@ -142,6 +142,8 @@ module Puppet::Util::ClassGen

     if is_constant_defined?(const)
       if options[:overwrite]
+        # JJM This can't possibly work as Puppet.info is not always a method in
+        # this point of the life-cycle.
         Puppet.info "Redefining #{name} in #{self}"
         remove_const(const)
       else
@@ -149,6 +151,7 @@ module Puppet::Util::ClassGen
           "Class #{const} is already defined in #{self}"
       end
     end
+    puts "Defining constant: #{const}"
     const_set(const, klass)

     const

Binding anonymous classes to constants

$ puppet apply -e 'notify { hello: }'
Defining constant: DestSyslog
Defining constant: DestFile
Defining constant: DestConsole
Defining constant: DestHost
Defining constant: DestReport
Defining constant: DestArray
Defining constant: DestEventlog
Defining constant: MetaParamNoop
Defining constant: MetaParamSchedule
Defining constant: MetaParamAudit
Defining constant: MetaParamCheck
Defining constant: MetaParamLoglevel
Defining constant: MetaParamAlias
Defining constant: MetaParamTag
Defining constant: MetaParamRequire
Defining constant: MetaParamSubscribe
Defining constant: MetaParamBefore
Defining constant: MetaParamNotify
Defining constant: MetaParamStage
Defining constant: Component
Defining constant: ParameterName
Defining constant: Log
Defining constant: Performance
Defining constant: Stage
Defining constant: ParameterName
Defining constant: Notify
Defining constant: Message
Defining constant: ParameterWithpath
Defining constant: ParameterName
Defining constant: Schedule
Defining constant: ParameterName
Defining constant: ParameterRange
Defining constant: ParameterPeriodmatch
Defining constant: ParameterPeriod
Defining constant: ParameterRepeat
Defining constant: ParameterWeekday
Defining constant: Filebucket
Defining constant: ParameterName
Defining constant: ParameterServer
Defining constant: ParameterPort
Defining constant: ParameterPath
Defining constant: File
Defining constant: ParameterPath
Defining constant: ParameterBackup
Defining constant: ParameterRecurse
Defining constant: ParameterRecurselimit
Defining constant: ParameterReplace
Defining constant: ParameterForce
Defining constant: ParameterIgnore
Defining constant: ParameterLinks
Defining constant: ParameterPurge
Defining constant: ParameterSourceselect
Defining constant: ParameterProvider
Defining constant: ProviderPosix
Defining constant: ProviderWindows
Defining constant: ParameterChecksum
Defining constant: Content
Defining constant: ParameterSource
Defining constant: Target
Defining constant: Ensure
Defining constant: Owner
Defining constant: Group
Defining constant: Mode
Defining constant: Type
Defining constant: ParameterSelinux_ignore_defaults
Defining constant: Seluser
Defining constant: Selrole
Defining constant: Seltype
Defining constant: Selrange
Defining constant: Ctime
Defining constant: Mtime
Defining constant: User
Defining constant: Ensure
Defining constant: Home
Defining constant: Uid
Defining constant: Gid
Defining constant: Comment
Defining constant: Shell
Defining constant: Password
Defining constant: Password_min_age
Defining constant: Password_max_age
Defining constant: Groups
Defining constant: ParameterName
Defining constant: ParameterMembership
Defining constant: ParameterSystem
Defining constant: ParameterAllowdupe
Defining constant: ParameterManagehome
Defining constant: Expiry
Defining constant: Roles
Defining constant: ParameterRole_membership
Defining constant: Auths
Defining constant: ParameterAuth_membership
Defining constant: Profiles
Defining constant: ParameterProfile_membership
Defining constant: Keys
Defining constant: ParameterKey_membership
Defining constant: Project
Defining constant: ParameterIa_load_module
Defining constant: Attributes
Defining constant: ParameterAttribute_membership
Defining constant: ParameterProvider
Defining constant: ProviderAix
Defining constant: ProviderDirectoryservice
Defining constant: ProviderUseradd
Defining constant: ProviderHpuxuseradd
Defining constant: ProviderLdap
Defining constant: ProviderPw
Defining constant: ProviderUser_role_add
Defining constant: ProviderWindows_adsi
Defining constant: Group
Defining constant: Ensure
Defining constant: Gid
Defining constant: Members
Defining constant: ParameterAuth_membership
Defining constant: ParameterName
Defining constant: ParameterAllowdupe
Defining constant: ParameterIa_load_module
Defining constant: Attributes
Defining constant: ParameterAttribute_membership
Defining constant: ParameterSystem
Defining constant: ParameterProvider
Defining constant: ProviderAix
Defining constant: ProviderDirectoryservice
Defining constant: ProviderGroupadd
Defining constant: ProviderLdap
Defining constant: ProviderPw
Defining constant: ProviderWindows_adsi
Defining constant: Whit
Defining constant: ParameterName
hello
/Stage[main]//Notify[hello]/message: defined 'message' as 'hello'
Finished catalog run in 0.03 seconds
Defining constant: Store

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment