metaclass
Version, currently 0.1.03 versions
- 0.1.2latestSep 11, 2016
- 0.1.1not indexedSep 11, 2016
- 0.1.0not indexedSep 11, 2016
github.com/mosop/metaclass
A Crystal library for manipulating class-level definitions.
Nothing has been indexed for 0.1.0 yet. The tag is recorded, its shard.yml has not been read, so the manifest and dependency list below are empty because they are unknown rather than because they are absent.
Installation
# Add this to your shard.yml
dependencies:
metaclass:
github: mosop/metaclass
version: ~> 0.1.0Then run:
shards installshard.yml
No shard.yml has been indexed for 0.1.0. You can read it on the repository.
Dependencies
Unknown: the shard.yml for this version has not been read yet.
README
This README is the one indexed from the repository at its latest ref, not from the tag for this version.
Metaclass
A Crystal library for manipulating class-level definitions.
Installation
Add this to your application's shard.yml:
dependencies:
metaclass:
github: mosop/metaclass
Features
Class Property
require "metaclass/object"
class Misc
metaclass!
class_getter faces = {:smile => ":)", :frown => ":("}
class_setter passcode = Random.rand(10000)
class_property movie = "Jaws"
end
Misc.faces # => {:smile => ":)", :frown => ":("}
Misc.faces = {:smile => ":D", :frown => ":{"} # raises error (getter only)
Misc.passcode = Random.rand(10000)
Misc.passcode # raises error (setter only)
Misc.movie # => "Jaws"
Misc.movie = "La Strada"
Misc.movie # => "La Strada"
Predicate
require "metaclass/object"
class Misc
metaclass!
class_getter? exists = true
class_setter? promise_broken = false
class_property? happy = false, neg: unhappy
end
Misc.exists? # => true
Misc.exists! # => raises error (getter only)
Misc.promise_broken!
Misc.promise_broken? # raises error (setter only)
Misc.happy? # => false
Misc.happy!
Misc.happy? # => true
Misc.unhappy!
Misc.happy? # => false
Computed Property
require "metaclass/object"
class Constant
metaclass!
class_getter uuid : String { SecureRandom.uuid }
end
class Inconstant
metaclass!
class_getter uuid : String, memo: false { SecureRandom.uuid }
end
Constant.uuid == Constant.uuid # => true
Inconstant.uuid != Inconstant.uuid # => true
Variable Inheritance
require "metaclass/object"
class A
metaclass!
class_getter inheritance, Hash(Symbol, String) do
{:a => "a"}
end
end
class B < A
metaclass!
inherited_class_getter inheritance do |parent|
parent.merge(:b => "b")
end
end
A.inheritance # => {:a => "a"}
B.inheritance # => {:a => "a", :b => "b"}
Usage
require "metaclass/object"
class A
metaclass!
end
Or more clean:
require "metaclass"
class A
Metaclass.metaclass!
end
And see Features
Release Notes
- v0.1.1
- Predicate
Contributing
- Fork it ( https://github.com/mosop/metaclass/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
Contributors
- mosop - creator, maintainer
Documentation
Built from the current release. The first visit to a release nobody has asked for starts its build.
Links
This release
- Version
0.1.0- Tagged
- Sep 11, 2016
- Commit
fe3f6df1bf3d- Indexed
- not yet
Dependents
No indexed shard depends on this one yet.
Repository
github.com/mosop/metaclass
Metadata
- Created
- Aug 12, 2026
- Updated
- Aug 15, 2026
- Synced
- Aug 15, 2026
- Versions
- 3