pendant is a small utility of accessor for Crystal.
This library is added hash-like accessor into your class.
Add it to Projectfile
deps do
github "MakeNowJust/pendant"
end
require "pendant"
class Accessory
# define properties and initializer
property name, owner
def initialize(@name, @owner); end
# include pendant module
# it defines `Accessory#[]`, `Accessory#[]?`, `Accessory#[]=` and
# `Accessory#keys` automatically.
include Pendant::Property
end
# create a new accessory
pendant = Accessory.new("pendant", "Alice")
# it can access via `[]` method
puts pendant[:name]
puts pendant["owner"]
$ crystal spec spec/spec.cr
- Fork it ( https://github.com/MakeNowJust/pendant/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
- MakeNowJust TSUYUSATO Kitsune - creator, maintainer