Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/hoppergee/active_method
Refactor your obscure method to a method object
https://github.com/hoppergee/active_method
method-object ruby
Last synced: 29 days ago
JSON representation
Refactor your obscure method to a method object
- Host: GitHub
- URL: https://github.com/hoppergee/active_method
- Owner: hoppergee
- License: mit
- Created: 2022-08-27T16:22:31.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2024-07-23T07:36:10.000Z (5 months ago)
- Last Synced: 2024-10-31T14:13:46.696Z (about 2 months ago)
- Topics: method-object, ruby
- Language: Ruby
- Homepage:
- Size: 106 KB
- Stars: 10
- Watchers: 2
- Forks: 0
- Open Issues: 4
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE.txt
- Code of conduct: CODE_OF_CONDUCT.md
Awesome Lists containing this project
README
# ActiveMethod
Method is an object in Ruby, but we need **a real method object**. Welcome to `ActiveMethod`!
- **Clean scope** without module
- **High maintainability** with tiny method objects
- Make wrting OO **easy**, then writing OO **everywhere**![](./hero.png)
## Installation
```bash
$ bundle add active_method
```## API
**It just do what a method do, and nothing else!**
### Define method object
```ruby
class User
include ActiveMethodactive_method :foo
active_method :bar, MyBar
active_method :build_one, class_method: true
endmodule Util
active_method :parse_url, module_function: true
end
```### Declaring arguments
```ruby
class Foo < ActiveMethod::Base
argument :a
argument :b, default: 2
keyword_argument :c
keyword_argument :d, default: 4def call
puts "a: #{a}, b: #{b}, c: #{c}, d: #{d}"
end
endUser.new.foo('aa', 3, c: 'cc', d: 5)
#=> a: aa, b: 3, c: cc, d: 5
```### Customize the owner name of the method
```ruby
class User
include ActiveMethod
attr_accessor :name
attr_accessor :fromal_name
active_method :hi
endclass Hi < ActiveMethod::Base
onwer :supportdef call
puts "Hi, I'm a #{support.fromal_name}. Please call me #{user.name}"
end
enduser = User.new
user.name = 'ActiveMethod'
user.fromal_name = 'method object'
user.hi
#=> Hi, I'm a method objectc, please call me ActiveMethod
```## Development
```bash
bundle install
meval rake # Run test
meval -a rake # Run tests against all Ruby versions and Rails versions
```## Contributing
Bug reports and pull requests are welcome on GitHub at https://github.com/hoppergee/active_method. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/hoppergee/active_method/blob/master/CODE_OF_CONDUCT.md).
## License
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
## Code of Conduct
Everyone interacting in the ActiveMethod project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/hoppergee/active_method/blob/master/CODE_OF_CONDUCT.md).