From: "rubyFeedback (robert heiler) via ruby-core" Date: 2023-03-31T18:02:00+00:00 Subject: [ruby-core:113062] [Ruby master Feature#19559] Introduce `Symbol#+@` and `Symbol#-@`, and eventually replace boolean arguments with symbols Issue #19559 has been updated by rubyFeedback (robert heiler). I think the idea is interesting; it also helps reduce the number of characters used. mame may like it for golf code. :) I do, however had, also think this may create a few issues. One I can think of the top of the head may be that newcomers to ruby may be a bit confused by the syntax. For instance: "foo".methods(false) Seems simpler to understand than: "foo".methods(-:inherit) (I understand that one can disagree here, since the second variant given by sawa carries additional information, in that there is a symbol given or symbol-like information given, e. g. the ":inherit" part.) I also think the "-:" and "+:" is not extremely elegant. This, of course, depends on one's preference about elegant syntax. But the idea itself is interesting. austin wrote: > Unless of course, this is a very early poisson d���Avril, in which case > I think we need to have more unary operators on symbols so we can > implement BF entirely with symbols. We could group that into oldschool evil.rb. All the weird parts of ruby that didn't quite manage to be approved by matz, but may still be added. :D Although perhaps it may be better to add as a gem or some other add-on. Vit wrote: ---------------------------------------- Feature #19559: Introduce `Symbol#+@` and `Symbol#-@`, and eventually replace boolean arguments with symbols https://bugs.ruby-lang.org/issues/19559#change-102597 * Author: sawa (Tsuyoshi Sawada) * Status: Open * Priority: Normal ---------------------------------------- I propose to define `Symbol#+@` and `Symbol#-@`, so that we can add positive or negative polarity to symbols. A possible implementation can be equivalent to what can be achieved by this: ```ruby class Symbol def -@; "-#{self}".to_sym end def +@; self end end ``` The intention behind this is to, eventually, replace boolean positional or keyword arguments with symbols so that, instead of this: ```ruby "foo".methods(false) gets(chomp: true) Integer("2.3", exception: false) ``` we can write like this: ```ruby "foo".methods(-:inherit) gets(+:chomp) Integer("2.3", -:exception) ``` -- https://bugs.ruby-lang.org/ ______________________________________________ ruby-core mailing list -- ruby-core@ml.ruby-lang.org To unsubscribe send an email to ruby-core-leave@ml.ruby-lang.org ruby-core info -- https://ml.ruby-lang.org/mailman3/postorius/lists/ruby-core.ml.ruby-lang.org/