package

github.com/OrelSokolov/attr_reader.cr

0.1.0 / published Oct 19, 2026 / repository

ruby attr_reader aliases for crystal

attr_reader.cr

Ruby-compat attr_reader / attr_writer / attr_accessor macros for Crystal — Rails-style declarations with zero dependencies.

Extracted from active_support.cr so low-level shards can use Rails-style attribute declarations without pulling in pg/redis transitively.

Usage

require "attr_reader_cr"

class User
  attr_reader :body, :content_type          # Ruby-style symbols
  attr_accessor name : String = "anon"      # typed declaration with default
  attr_writer :secret                       # generates secret=
end

Mapping

Rubyidiomatic Crystalattr_reader.cr
attr_reader :foogetter fooattr_reader :foo
attr_writer :foosetter fooattr_writer :foo
attr_accessor :fooproperty fooattr_accessor :foo

All forms delegate to the stdlib getter/setter/property macros, so typed declarations and defaults pass straight through:

attr_accessor name : String = "anon", level : Int32 = 0

Installation

  1. Add the dependency to shard.yml:

    dependencies:
      attr_reader_cr:
        github: OrelSokolov/attr_reader.cr
        version: ~> 0.1.0
  2. Run shards install

License

MIT

API

  • Object

    Object is the base type of all Crystal objects.