Re: Metaprogrammatically defining methods with required, optional, required keyword and optional keyword parameters?
John Carter <[email protected]> Tue, 18 Jun 2019 12:15:23 +1200
| Newsgroups | gmane.comp.lang.ruby.general |
|---|---|
| Message-ID | <CAFD1m3Ed-F-UgDn0K7sjUCtV1X_weJoViEMhLA3NuMRPDLq0Xw@mail.gmail.com> |
Yup. That's exactly what I'm looking for. Thanks! I must be getting old or something... I have looked up and down https://ruby-doc.com/core/ and https://rubyreferences.github.io/rubyref and can't see where they say blocks have those features as well. Can you anyone put me out of my misery and point me at the Right part of the FM To R? On Mon, Jun 17, 2019 at 6:58 PM Marvin Gülker <[email protected]> wrote: > Am 17. Juni 2019 um 10:20 Uhr +1200 schrieb John Carter: > > However modern ruby now has required parameters, default parameters, > > required keyword parameters and optional keyword parameters and an > > optional a block parameter. > > [...] > > Any idea how to define (at run time) the parameter list for a method? > > Here's your example with define_method: > > define_method(:foo) do |bar, baz, but = 0, joke:, nojoke: 10, &block| > p [bar, baz, but, joke, nojoke, block] > block.call > end > > foo(1, 2, joke: 50){puts "I'm a block!"} > > Is that what you are looking for? > > -- > Blog: https://mg.guelker.eu > > Unsubscribe: <mailto:[email protected]?subject=unsubscribe> > <http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-talk> > -- John Carter Phone : (64)(3) 358 6639 Tait Electronics PO Box 1645 Christchurch New Zealand -- This Communication is Confidential. We only send and receive email on the basis of the terms set out at www.taitradio.com/email_disclaimer <http://www.taitradio.com/email_disclaimer> Unsubscribe: <mailto:[email protected]?subject=unsubscribe> <http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-talk>