Skip to content

How can I use method_source to get the source of a Rails scope? #70

@benlieb

Description

@benlieb

I have a Rails scope:

  scope :positive_amount,                    -> { where("amount > 0") }

But when I do:

Transaction.method(:positive_amount).source.display

I get:

            singleton_class.send(:define_method, name) do |*args|
              scope = all
              scope = scope._exec_scope(*args, &body)
              scope = scope.extending(extension) if extension
              scope
            end

Not the -> { where("amount > 0") } that I'd like.

Any ideas?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions