[#104169] [Ruby master Feature#17938] Keyword alternative for boolean positional arguments — matheusrichardt@...

Issue #17938 has been reported by matheusrich (Matheus Richard).

12 messages 2021/06/04

[#104213] [Ruby master Feature#17942] Add a `initialize(public @a, private @b)` shortcut syntax for defining public/private accessors for instance vars — tyler@...

Issue #17942 has been reported by TylerRick (Tyler Rick).

6 messages 2021/06/09

[#104288] [Ruby master Bug#17992] Upstreaming the htmlentities gem into CGI#.(un)escape_html — alexandermomchilov@...

Issue #17992 has been reported by AMomchilov (Alexander Momchilov).

9 messages 2021/06/15

[#104338] [Ruby master Misc#17997] DevelopersMeeting20210715Japan — mame@...

Issue #17997 has been reported by mame (Yusuke Endoh).

10 messages 2021/06/17

[#104361] [Ruby master Bug#18000] have_library doesn't work when ruby is compiled with --disable-shared --disable-install-static-library — jean.boussier@...

Issue #18000 has been reported by byroot (Jean Boussier).

9 messages 2021/06/18

[#104401] [Ruby master Feature#18007] Help developers of C extensions meet requirements in "doc/extension.rdoc" — mike.dalessio@...

Issue #18007 has been reported by mdalessio (Mike Dalessio).

16 messages 2021/06/25

[#104430] [Ruby master Bug#18011] `Method#parameters` is incorrect for forwarded arguments — josh.cheek@...

Issue #18011 has been reported by josh.cheek (Josh Cheek).

12 messages 2021/06/29

[ruby-core:104184] [Ruby master Feature#12913] A way to configure the default maximum width of pp

From: mame@...
Date: 2021-06-07 07:16:48 UTC
List: ruby-core #104184
Issue #12913 has been updated by mame (Yusuke Endoh).


So, some people (including @ko1) have a custom to pass keyword arguments to Kernel#pp:

```
foo = 42
bar = 43
pp(foo: foo, bar: bar) #=> {:foo=>42, :bar=>43}
```

Unfortunately, introducing keyword arguments to `Kernel#pp` breaks their custom.

How about introducing `pp_out` and `pp_width` keywords? It is a bit dirty, but good enoguh.

```diff
diff --git a/lib/pp.rb b/lib/pp.rb
index 72480e5304..b090d2bdeb 100644
--- a/lib/pp.rb
+++ b/lib/pp.rb
@@ -91,6 +91,15 @@ def PP.singleline_pp(obj, out=$>)
   def PP.mcall(obj, mod, meth, *args, &block)
     mod.instance_method(meth).bind_call(obj, *args, &block)
   end
+
+  def PP.width_for(out)
+    begin
+      require 'io/console'
+      _, width = out.winsize
+    rescue LoadError, NoMethodError, Errno::ENOTTY
+    end
+    (width || ENV['COLUMNS']&.to_i&.nonzero? || 80) - 1
+  end
   # :startdoc:

   if defined? ::Ractor
@@ -596,12 +605,21 @@ def pretty_inspect
     PP.pp(self, ''.dup)
   end

-  # prints arguments in pretty form.
+  # Prints arguments in pretty form.
   #
   # pp returns argument(s).
-  def pp(*objs)
+  #
+  # It prints to +$>+ by default. A keyword argument +pp_out+ is given,
+  # it is used as the output target.
+  #
+  # The output is fitted to the width of the console by default.
+  # A keyword +pp_width+ is used if given.
+  def pp(*objs, **kw)
+    out = kw.delete(:pp_out) || $>
+    width = kw.delete(:pp_width) || PP.width_for(out)
+    objs << kw unless kw.empty?
     objs.each {|obj|
-      PP.pp(obj)
+      PP.pp(obj, out, width)
     }
     objs.size <= 1 ? objs.first : objs
   end
diff --git a/prelude.rb b/prelude.rb
index b1e477a3ea..b8c564e84e 100644
--- a/prelude.rb
+++ b/prelude.rb
@@ -10,9 +10,9 @@ def irb
 end

 module Kernel
-  def pp(*objs)
+  def pp(...)
     require 'pp'
-    pp(*objs)
+    pp(...)
   end

   # suppress redefinition warning
```

----------------------------------------
Feature #12913: A way to configure the default maximum width of pp
https://bugs.ruby-lang.org/issues/12913#change-92364

* Author: mame (Yusuke Endoh)
* Status: Assigned
* Priority: Normal
* Assignee: nobu (Nobuyoshi Nakada)
----------------------------------------
How about having an easy way to configure the maximum width of a line of `pp` output?
Currently, `pp` accepts the maximum width as an optional argument:

    pp(big_array, $>, 120)

However, this is obviously too long for a useful debugging-purpose method like `pp`.  Even worse, we must add the fragment "`, $>, 120`" to all calls to `pp`.  I don't feel this is reasonable.

The patch attached provides `PP.default_maxwidth=` and `PP.default_maxwidth`, which can be used to configure the default setting of the maxwidth.

    PP.default_maxwidth = 1
    pp([1, 2, 3])
    #=> [1,
    #    2,
    #    3]

Akr-san, what do you think?

---Files--------------------------------
pp-default-maxwidth.patch (1.05 KB)


-- 
https://bugs.ruby-lang.org/

Unsubscribe: <mailto:ruby-core-request@ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>

In This Thread

Prev Next