Skip to content

makenowjust/pendant

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

28 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

pendant

pendant is a small utility of accessor for Crystal.

This library is added hash-like accessor into your class.

travis-ci.org docrystal.org gratipay.com flattr.com

Installation

Add it to Projectfile

deps do
  github "MakeNowJust/pendant"
end

Usage

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"]

Development

$ crystal spec spec/spec.cr

Contributing

  1. Fork it ( https://github.com/MakeNowJust/pendant/fork )
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create a new Pull Request

Contributors