sixarm_ruby_defining
SixArm.com » Ruby » Meta-programming to detect when you are defining/redefining a method
Science Score: 44.0%
This score indicates how likely this project is to be science-related based on various indicators:
-
✓CITATION.cff file
Found CITATION.cff file -
✓codemeta.json file
Found codemeta.json file -
✓.zenodo.json file
Found .zenodo.json file -
○DOI references
-
○Academic publication links
-
○Committers with academic emails
-
○Institutional organization owner
-
○JOSS paper metadata
-
○Scientific vocabulary similarity
Low similarity (7.4%) to scientific vocabulary
Keywords
Repository
SixArm.com » Ruby » Meta-programming to detect when you are defining/redefining a method
Basic Info
- Host: GitHub
- Owner: SixArm
- License: other
- Language: Ruby
- Default Branch: main
- Homepage: http://sixarm.com
- Size: 319 KB
Statistics
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
- Releases: 0
Topics
Metadata Files
README.md
SixArm.com → Ruby →
Class#defining and #redefining metaprogramming methods
- Doc: http://sixarm.com/sixarm_ruby_defining/doc
- Gem: http://rubygems.org/gems/sixarm_ruby_defining
- Repo: http://github.com/sixarm/sixarm_ruby_defining <!--header-shut-->
Introduction
Meta-programming method that we call when we are defining (or redefining) a class method, to detect if we're accidentally overriding an existing method.
- Suppose we're creating a class defining a method named "foo".
- Before we do it, we want to check to see if the method "foo" already exists, so we don't accidentally override it.
- We call #defining which asks if the method "foo" already exists then gives us feedback if we can proceed safely.
- We call #redefining if we know the method already exists and we are overriding it/
Example of defining a new method:
class C
defining "foo"
#=> return true; it's safe to proceed because #foo is not defined.
Example of error detection:
class C
defining "hash"
#=> raise an error; it's not safe to proceed because #hash is already defined.
Example of intentionally overriding an existing method:
class C
redefining "hash"
#=> return true; it's safe to proceed because #hash is already defined.
Example of error detection:
class C
redefining "foo"
#=> raise an error; it's not safe to proceed because #foo is not yet defined.
For docs go to http://sixarm.com/sixarm_ruby_defining/doc
Want to help? We're happy to get pull requests.
Install
Gem
To install this gem in your shell or terminal:
gem install sixarm_ruby_defining
Gemfile
To add this gem to your Gemfile:
gem 'sixarm_ruby_defining'
Require
To require the gem in your code:
require 'sixarm_ruby_defining'
Multiple method names
The methods can take multiple names.
Example of #defining multiple names:
class C
defining "foo", "goo", "hoo"
#=> return true if we're safe i.e. all the methods are not yet defined,
#=> otherwise raise an error for each method that is already defined.
Example of #redefining multiple names:
class C
redefining "hash", "inspect", "equal?"
#=> return true if all the methods are already defined,
#=> otherwise raise an error for each method that is not yet defined.
Intermixing
We can intermix the methods however we like:
class C
...
defining "foo", "goo"
...
redefining "hash", "inspect"
...
defining "goo"
...
redefining "equals?"
Customization for success and failure
For meta-programming we can customize what happens when #defining and #redefining encounter methods that are
defining_success: called by #defining when a method name is not yet defined; this will return true.
defining_failure: called by #defining when a method name is already defined; tihs will raise an error.
redefining_success: called by #redefining when a method name is already defined; this will return true.
redefining_failure: called by #redefining when a method name is not yet defined; tihs will raise an error.
Owner
- Name: SixArm
- Login: SixArm
- Kind: organization
- Email: sixarm@sixarm.com
- Location: San Francisco
- Website: http://sixarm.com
- Twitter: sixarm
- Repositories: 580
- Profile: https://github.com/SixArm
SixArm Software
Citation (CITATION.cff)
cff-version: 1.2.0
title: SixArm.com → Ruby → <br> Class#defining and #redefining metaprogramming methods
message: >-
If you use this work and you want to cite it,
then you can use the metadata from this file.
type: software
authors:
- given-names: Joel Parker
family-names: Henderson
email: joel@joelparkerhenderson.com
affiliation: joelparkerhenderson.com
orcid: 'https://orcid.org/0009-0000-4681-282X'
identifiers:
- type: url
value: 'https://github.com/SixArm/sixarm_ruby_defining/'
description: SixArm.com → Ruby → <br> Class#defining and #redefining metaprogramming methods
repository-code: 'https://github.com/SixArm/sixarm_ruby_defining/'
abstract: >-
SixArm.com → Ruby → <br> Class#defining and #redefining metaprogramming methods
license: See license file
GitHub Events
Total
- Push event: 1
Last Year
- Push event: 1
Committers
Last synced: 11 months ago
Top Committers
| Name | Commits | |
|---|---|---|
| Joel Parker Henderson | j****l@j****m | 87 |
Committer Domains (Top 20 + Academic)
Issues and Pull Requests
Last synced: 9 months ago
All Time
- Total issues: 0
- Total pull requests: 0
- Average time to close issues: N/A
- Average time to close pull requests: N/A
- Total issue authors: 0
- Total pull request authors: 0
- Average comments per issue: 0
- Average comments per pull request: 0
- Merged pull requests: 0
- Bot issues: 0
- Bot pull requests: 0
Past Year
- Issues: 0
- Pull requests: 0
- Average time to close issues: N/A
- Average time to close pull requests: N/A
- Issue authors: 0
- Pull request authors: 0
- Average comments per issue: 0
- Average comments per pull request: 0
- Merged pull requests: 0
- Bot issues: 0
- Bot pull requests: 0
Top Authors
Issue Authors
Pull Request Authors
Top Labels
Issue Labels
Pull Request Labels
Dependencies
- minitest >= 5.7.0, < 6 development
- rake > 10.4.2, < 11 development
- simplecov >= 0.10.0, < 2 development
- sixarm_ruby_minitest_extensions >= 1.0.8, < 2 development
- actions/checkout v3 composite
- ruby/setup-ruby v1 composite
- bundler 2.3.26
- docile 1.4.0
- minitest 5.18.0
- rake 12.3.3
- simplecov 0.22.0
- simplecov-html 0.12.3
- simplecov_json_formatter 0.1.4
- sixarm_ruby_defining 2.0.2
- sixarm_ruby_minitest_extensions 1.1.1