matching.cr
matching
Traversing the fields of a structure, matching and assigning values.
Installation
-
Add the dependency to your
shard.yml
:dependencies: matching: github: Hentioe/matching.cr
-
Run
shards install
Usage
require "matching"
class Person
property name : String
property age : Int32
property hobbies : Array(String)
def initialize(@name, @age, @hobbies)
end
end
p1 = Person.new("John", 18, ["Swimming"])
p2 = Person.new("Mary", 21, [] of String)
name : String? = nil
Matching.matching(p1, name: name, age: 18, hobbies: ["Swimming"])
pp name # => "John"
Matching.matching(p1, name: name, age: 21)
pp name # => nil
age : Int32? = nil
Matching.matching(p2, name: "Mary", age: age)
pp age # => 21
Contributing
- Fork it (https://github.com/Hentioe/matching/fork)
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create a new Pull Request
Contributors
- Hentioe - creator and maintainer
Repository
matching.cr
Owner
Statistic
- 2
- 1
- 0
- 1
- 0
- almost 5 years ago
- December 26, 2019
License
MIT License
Links
Synced at
Wed, 06 Nov 2024 18:15:23 GMT
Languages