-
Notifications
You must be signed in to change notification settings - Fork 312
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
Deferred defaults for Dash #34
Conversation
+1 Please merge this Pull Request! Another important use case is (lazy) dynamic method invocation: MyDash.property :width, default: proc { default_width }
def default_width
# ...
end |
+1 deferred defaults would be an awesome feature for Dash. |
Would most definitely like this merged... |
yield value if block_given? | ||
value | ||
# If the value is a lambda, proc, or whatever answers to call, eval the thing! | ||
if value.respond_to? :call |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How do you feel about changing this to value.is_a? Proc
? It's unlikely that users will assign an object that responds to call
accidentally, but it'd be very unexpected behavior. A contrived example would be defaulting a middleware class as a value. In console, it looks like Proc.new
, proc {...}
and lambda {...}
all return things that are Proc
objects.
Thanks for building out this useful feature! I'm going through an cleaning out issues and pulls and would love to merge this. Could you look over the comments I made and see if they're reasonable? |
Fixed everything per everybody's comments. |
🤘 |
Its desirable to have Procs that populate a default value for a key in Dash. Consider a key that generates a GUID and/or populates created_at may be wanted for an object:
This pull request adds support for lazily evaluated defaults to Dash to support this use case.