Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Functional Ruby - Notes
- - immutable (don't modify inputs)
- - prefer stateless objects
- ## Prevent access to initial state
- ```ruby
- class UserQuery
- def initialize(query)
- @query = query
- end
- def with(query)
- self.class.new(query)
- end
- def call
- query.execute
- end
- end
- ```
- Consider:
- use initializer to ONLY inject dependencies
- pass ALL inputs to methods
- - less coupling
- - instantiate objects once, use them numerous times
- - data (from db or external API) becomes first class
- - make sure this is well defined so that you can compose
- Object composition:
- ```ruby
- input = { name: "Person" }
- persist_person.call(
- validate.call(
- coerce.call(input)
- )
- )
- ```
- __Lazy function calling__
- Partially implement function based on arguments passed in
Add Comment
Please, Sign In to add comment