Coder Social home page Coder Social logo

Comments (7)

egisatoshi avatar egisatoshi commented on June 7, 2024

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.

mirakui avatar mirakui commented on June 7, 2024

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.

egisatoshi avatar egisatoshi commented on June 7, 2024

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.

mirakui avatar mirakui commented on June 7, 2024

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.

sorah avatar sorah commented on June 7, 2024

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.

egisatoshi avatar egisatoshi commented on June 7, 2024

@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.

egisatoshi avatar egisatoshi commented on June 7, 2024

@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 photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.