Code Monkey home page Code Monkey logo

Comments (7)

codella avatar codella commented on June 17, 2024

Well, good that this has been brought up! In particular, this is clashing with a match method that is supposed to be available whenever you want to define an RSpec matcher by yourself, for instance:

require 'rspec/expectations'

RSpec::Matchers.define :be_a_multiple_of do |expected|
  match do |actual|
    actual % expected == 0
  end
end

from rltk.

libo avatar libo commented on June 17, 2024

Well @codella actually I have found a workaround.

in your node class you could do

require 'rltk/ast'
Object.send :undef_method, :match

class BaseNode < RLTK::ASTNode
  ..
end

But, yes... not very elegant. It would be better if we just include Filigree::Destructurable and avoid defining match on the Object class

from rltk.

chriswailes avatar chriswailes commented on June 17, 2024

This is certainly something I can work on. I might need your help with testing though, as I currently don't have any environment that causes this problem.

I'd appreciate it if you could also leave me a short description of how/why you are using RLTK. This helps me understand how people are using RLTK and if it is meeting people's needs.

from rltk.

chriswailes avatar chriswailes commented on June 17, 2024

So, my match is a function and not a method of some particular object. It looks like Ruby might implement functions by making them methods of Object, but that doesn't always seem to be the case. Can you get your code to work by using self.match instead of match? If that doesn't work, the only solution I see is to re-name the Filigree-provided function to something like pmatch (for 'pattern-match').

from rltk.

libo avatar libo commented on June 17, 2024

Hi
At this moment in time I can't disclose what we are working on, I am sorry. Anyway we have all the intentions to opensource the project as soon as possible.

The issue we see here is that after require 'filigree/match' any constants, method or globals within the loaded source file will be available in the calling program’s global namespace.

When you do a

def match
  puts "foo"
end

you are actually defining a method in the ruby main object

» irb
def match; puts "foo"; end

method(:match).owner
 => Object

self
 => main

Instead of renaming it with pmatch (so to introduce some sort of naming spacing "p") why don't you go for a real namespace and use a module

module Filigree 
  def match
    puts "foo"
  end
end

The function will be still available as a global ::Filigree.match

from rltk.

libo avatar libo commented on June 17, 2024

I can confirm that this would work

require 'rspec/expectations'

RSpec::Matchers.define :be_a_multiple_of do |expected|
  self.match do |actual|
    actual % expected == 0
  end
end

The point is that rspec is loaded before Filigree and hence the latest will define a match method that will override the one in rspec even if they define it in a module:
https://github.com/rspec/rspec-expectations/blob/7628434b8e10620669bf34f9b341acbd7e5946ee/lib/rspec/matchers/dsl.rb#L57

(is still a supposition, I am trying to prove it but it's not easy to find out what is going in rspec sourcecode)

In my humble opinion your match function as it is now is hitting a bit the principle of least astonishment .

Sorry for my rant :-)

from rltk.

chriswailes avatar chriswailes commented on June 17, 2024

This issue was fixed by moving the match function provided by Filigree into the Filigree namespace. Please file any followup issues to the Filigree Github page.

Relevant patch: chriswailes/filigree@ead2f44

from rltk.

Related Issues (20)

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.