Comments (7)
Thank you for your information.
I've updated the code to add methods to existing ::Set
provided by the standard library.
https://github.com/egison/egison-ruby/blob/v0.2.1/lib/egison/matcher.rb
How do you think about it?
By the way, the name of gem is "egison", not "edison".
from egison-ruby.
Sorry for typo 🙇
IMO, gems should not extend existing standard classes as possible except special cases.
For example, I think everyone who uses activesupport knows that activesupport extends lots of existing Ruby classes.
But people who want to do the cool pattern matching using egison-ruby may not expect that egison-ruby extends Ruby's Set
.
from egison-ruby.
I don't want to type ::Egison::Set
for each pattern matching is not cool though I' also don't want to extend Ruby's Set
.
Are there good ways to solve this problem?
from egison-ruby.
I think one of ruby-ish way is:
require 'egison'
include Egison # <- Import methods of Egison module into the namespace
match_all([1, 2, 3]) do # <- should be Egision.match_all instead of Kernel.match_all
with(Set.(_a, _b, *_)) do # <- Set means Egison::Set
[a, b]
end
end
In this way, you can simply write Set
to use ::Egison::Set
.
from egison-ruby.
as @mirakui said, user expects egison to do pattern matching, but not expects to extend ::Set
.
Cons of extending existing classes is when other library or user is extending same class with same method name, it'll be a strange bug due to conflict. Hard to investigate.
I recommend to not extend existing classes if you don't have proper reason to extend.
using module_eval(Egison)
to inject namespace in Egison.match_all
implementation is better?
from egison-ruby.
@mirakui @sorah Thank you so much for your advice!
I think your approach is great and I'd like to try with your approach.
However, the problem is I'm not familiar enough to Ruby to update the code at once.
If it is not hard for you to refine code, would you help me?
from egison-ruby.
@mirakui @sorah I deepened my knowledge on Ruby and think I've solved this issue. Please check it if you have a chance.
from egison-ruby.
Related Issues (4)
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from egison-ruby.