Sha256: 8b1266eda997628c8c13cb428033bbb53daeb3bdb9f1ed02a3ac5403e1d8a836
Contents?: true
Size: 1.15 KB
Versions: 2
Compression:
Stored size: 1.15 KB
Contents
# frozen-string-literal: true # # The meta_def extension is designed for backwards compatibility # with older Sequel code that uses the meta_def method on # Database, Dataset, and Model classes and/or instances. It is # not recommended for usage in new code. To load this extension: # # Sequel.extension :meta_def # # Related module: Sequel::Metaprogramming Sequel::Deprecation.deprecate("The meta_def extension", "Replace meta_def usage with define_singleton_method") # module Sequel # Contains meta_def method for adding methods to objects via blocks. # Only recommended for backwards compatibility with existing code. module Metaprogramming # Define a method with the given name and block body on the receiver. # # ds = DB[:items] # ds.meta_def(:x){42} # ds.x # => 42 def meta_def(name, &block) (class << self; self end).send(:define_method, name, &block) end end Database.extend Metaprogramming Database.send(:include, Metaprogramming) Dataset.extend Metaprogramming Dataset.send(:include, Metaprogramming) if defined?(Model) Model.extend Metaprogramming Model.send(:include, Metaprogramming) end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
sequel-4.49.0 | lib/sequel/extensions/meta_def.rb |
sequel-4.48.0 | lib/sequel/extensions/meta_def.rb |