attr_reader_cr

Version, currently 0.1.01 version
  • 0.1.0latestOct 19, 2026

github.com/OrelSokolov/attr_reader.cr

ruby attr_reader aliases for crystal

0 stars
12 dependents
License: not declared

Installation

# Add this to your shard.yml
dependencies:
  attr_reader_cr:
    github: OrelSokolov/attr_reader.cr
    version: ~> 0.1.0

Then run:

shards install

shard.yml

Crystal
>= 1.21.0

Dependencies

This version declares no dependencies.

README

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