New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Any plans to support module arguments as mentioned in the README? #1
Comments
Hi! I haven't really touched or used this code in a decade (!) but just for fun, I tried it. If you only need to use the module arguments on the class level (not inside instance methods), you can do something like this: class ::Object
def self.augment(*mods, **args)
mods.each { |mod| class_exec(**args, &mod.augmentation) }
end
end
class ::Module
def augmentation(&block)
@augmentation ||= block
end
end
module Person
augmentation do |age:|
if age
def age
42
end
end
end
end
class AgefulCustomer
augment Person, age: true
end
class AgelessCustomer
augment Person, age: false
end
p AgefulCustomer.new.age
p AgelessCustomer.new.age # Boom! Undefined method! |
Cool, thank you!
On Sun, Mar 29, 2020 at 8:29 AM Henrik Nyh ***@***.***> wrote:
Hi! I haven't really touched or used this code in a decade (!) but just
for fun, I tried it. If you only need to use the module arguments on the
class level (not inside instance methods), you can do something like this:
class ::Object
def self.augment(*mods, **args)
include *mods
mods.each { |mod| class_exec(**args, &mod.augmentation) }
end
end
class ::Module
def augmentation(&block)
@Augmentation ||= block
end
end
module Person
augmentation do |age:|
if age
def age
42
end
end
end
end
class AgefulCustomer
augment Person, age: true
end
class AgelessCustomer
augment Person, age: false
end
p AgefulCustomer.new.age
p AgelessCustomer.new.age # Boom! Undefined method!
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#1 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AABNMAJF3X2V7VE7WY6775DRJ45KVANCNFSM4LUPUUHQ>
.
--
…--
Kevin Southworth
Web Ascender
(517) 455-7837 x102
kevin.southworth@webascender.com
|
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Just wondering if you have any plans to add support for module arguments, as mentioned in the "To-Do" section of the readme?
https://github.com/henrik/augmentations#to-do
The text was updated successfully, but these errors were encountered: