Sha256: 78c10725017c1da9f59a24d488530daa2a63c395e7861cd4a7d6b6026a446bb1
Contents?: true
Size: 914 Bytes
Versions: 15
Compression:
Stored size: 914 Bytes
Contents
class Kookaburra # @private module DependencyAccessor # Creates a private attr_reader on the class that will raise an exception if # the attribute has a nil value when it is called. Useful for attributes # that can optionally be set in an object's constructor but it is not an # error for them to be missing unless something actually wants to use them. def dependency_accessor(*names) names.each { |name| define_dependency_accessor(name) } end private def define_dependency_accessor(name) define_method(name) do class_name = self.class.name class_name.sub!(/^$/, 'an Anonymous Class!!!') instance_variable_get("@#{name}") or raise "No %s object was set on %s initialization." \ % [name, class_name] end define_method("#{name}=") do |value| instance_variable_set("@#{name}", value) end end end end
Version data entries
15 entries across 15 versions & 1 rubygems