attr_reader.cr

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

Ruby idiomatic Crystal attr_reader.cr
attr_reader :foo getter foo attr_reader :foo
attr_writer :foo setter foo attr_writer :foo
attr_accessor :foo property foo attr_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

Repository

attr_reader.cr

Owner
Statistic
  • 0
  • 0
  • 0
  • 11
  • 0
  • about 5 hours ago
  • October 19, 2026
License

Links
Synced at

Mon, 19 Oct 2026 15:57:40 GMT

Languages