8 Commits

Author SHA1 Message Date
Yukihiro "Matz" Matsumoto 3fc7dd1858 mruby-proc-ext: Proc#curry should check max arity for lambdas
`lambda {|a, b=nil|}.curry(3)` used to silently return a curried Proc;
CRuby raises `ArgumentError` because the lambda accepts at most 2 args.
Use `self.parameters` to compute the upper bound (count `:req`/`:opt`
entries, unbounded if `:rest`/`:keyrest` is present) and add the
corresponding range check alongside the existing minimum check.

close #2855

Co-authored-by: Claude <noreply@anthropic.com>
2026-05-11 14:06:28 +09:00
Yukihiro "Matz" Matsumoto 6b263ee577 mruby-proc-ext: add comprehensive call-seq documentation for Proc extensions
Added complete call-seq documentation for all extended Proc methods in
mrblib/proc.rb (6 methods):

## Proc Extension Methods:

- ===: case equality operator for use in case statements, enables proc
  objects as targets in when clauses for pattern matching

- yield: compatibility method equivalent to call, provided for API
  consistency with block yield semantics

- to_proc: protocol method that returns self, part of the standard
  to_proc conversion protocol for Proc objects

- curry: creates curried procs for partial application and functional
  programming patterns, supports optional arity specification with
  proper lambda arity validation

- << (left composition): proc composition operator that calls other_proc
  first then this proc, enabling right-to-left function composition

- >> (right composition): proc composition operator that calls this proc
  first then other_proc, enabling left-to-right function composition

Co-authored-by: Atlassian Rovo Dev
2025-08-14 10:52:45 +09:00
dearblue c4bca7cbb3 Align "wrong number of arguments" messages
Make "N for M" into the form "given N, expected M".

As I worked, I noticed that the `argnum_error()` function had a part to include the method name in the message.
I think this part is no longer needed by https://github.com/mruby/mruby/pull/5394.

  - Before this patch

    ```console
    % bin/mruby -e '[1, 2, 3].each 0'
    trace (most recent call last):
            [1] -e:1
    -e:1:in each: 'each': wrong number of arguments (1 for 0) (ArgumentError)
    ```

  - After this patch

    ```console
    % bin/mruby -e '[1, 2, 3].each 0'
    trace (most recent call last):
            [1] -e:1
    -e:1:in each: wrong number of arguments (given 1, expected 0) (ArgumentError)
    ```
2021-11-28 18:21:29 +09:00
dearblue 16e388863a Fixed some methods where keyword arguments are not passed 2021-11-24 23:35:42 +09:00
dearblue 9a9e12a129 Add proc composition feature (CRuby-2.6 compatible)
- Proc#<< and Proc#>>
  - Method#<< and Method#>>
2019-01-03 18:16:26 +09:00
Yukihiro "Matz" Matsumoto 05f377dee4 Use __send__ instead of send. 2018-09-01 11:02:59 +09:00
cremno 69b4c1648a Proc#curry should preserve lambdas 2015-06-22 16:35:54 +02:00
h2so5 1a375c6fd4 Add mruby-proc-ext 2013-04-17 22:59:57 +09:00