ruby-core@ruby-lang.org archive (unofficial mirror)
 help / color / mirror / Atom feed
* [ruby-core:46799] [ruby-trunk - Feature #6801][Open] String#~ for a here document
@ 2012-07-27  4:16 merborne (kyo endo)
  2012-07-27  5:19 ` [ruby-core:46800] [ruby-trunk - Feature #6801] " nobu (Nobuyoshi Nakada)
                   ` (10 more replies)
  0 siblings, 11 replies; 12+ messages in thread
From: merborne (kyo endo) @ 2012-07-27  4:16 UTC (permalink / raw)
  To: ruby-core


Issue #6801 has been reported by merborne (kyo endo).

----------------------------------------
Feature #6801: String#~ for a here document
https://bugs.ruby-lang.org/issues/6801

Author: merborne (kyo endo)
Status: Open
Priority: Normal
Assignee: 
Category: 
Target version: 


=begin
Let me propose a new method ((*String#~*)) for a here document.

次のような実装の((*String#~*))を提案します。

    class String
      def ~
        margin = scan(/^ +/).map(&:size).min
        gsub(/^ {#{margin}}/, '')
      end
    end

This is for removing leading margins of a here document.

これはヒアドキュメントにおける先頭マージンを除去するためのものです。

    class ATool
      def self.help
        lines = ~<<-EOS
                  Instruction of `#{self}`
    
        `#{self}` is one of a great tool in the world.
           This helps you a lot on your daily work.
          Your life will be changed with `#{self}`!!
               Everyone knows about `#{self}`.
            So, You can ask them to learn `#{self}`
    
                    Just Use `#{self}`
    
                       from Today!
        EOS
        lines
      end
    end
    
    puts ATool.help
    
    # >>           Instruction of `ATool`
    # >> 
    # >> `ATool` is one of a great tool in the world.
    # >>    This helps you a lot on your daily work.
    # >>   Your life will be changed with `ATool`!!
    # >>        Everyone knows about `ATool`.
    # >>     So, You can ask them to learn `ATool`
    # >> 
    # >>             Just Use `ATool`
    # >> 
    # >>                from Today!

you can put a tilde sign just before the "<<" characters to call String#~, just like putting a minus sign after "<<" to indent the terminator. This is achieved with uniqueness of tilde sign method, which takes the receiver object on the right-hand side.

If you define String#unindent for this purpose, you put `.unindent` after EOS. I think its less elegant than a tilde.

"<<"文字の直前にチルダを置くことで、String#~を呼び出すことができます。これはチルダ記号のメソッドが、そのレシーバオブジェクトを右側に取るという特徴によって実現されます。仮にこの目的のためにString#unindentを定義した場合は、EOSの後に`.unindent`を書くことになりますが、これはチルダに比べると美しくありません。

I understand that this is not general method for string but just for here document. However, I think using a tilde as a method is very restricted because it can't take parameters and is difficult to read the meanings or behavior from the sign. From this, there are few tilde methods within built-in classes of ruby inspite of its uniqness(only for Fixnum, Bignum and Regexp).

so, I think using tilde for the above purpose is the one of the few good chances.

Thank you for your consideration.

このメソッドがStringのための汎用的なものでなく、ヒアドキュメント専用であるということに問題がある点は理解しています。しかし、チルダをメソッドとして使える機会は、それが引数を取れないことと、その記号からはその意味や動作を察することは難しいことから、非常に限られていると想像します。故に、そのユニークさにも拘らず、Rubyの組み込みクラスでの使用例は少しです(Fixnum, BignumおよびRegexpでだけ)。

従って、上記目的でチルダを使うことは、数少ない良い機会であると考えます。

以上、ご検討のほどよろしくお願い致します。

This is based on the following my Japanese blog post.

((<URL:http://melborne.github.com/2012/04/27/ruby-heredoc-without-leading-whitespace/>))
=end


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

^ permalink raw reply	[flat|nested] 12+ messages in thread

* [ruby-core:46800] [ruby-trunk - Feature #6801] String#~ for a here document
  2012-07-27  4:16 [ruby-core:46799] [ruby-trunk - Feature #6801][Open] String#~ for a here document merborne (kyo endo)
@ 2012-07-27  5:19 ` nobu (Nobuyoshi Nakada)
  2012-07-27 10:23 ` [ruby-core:46807] " Eregon (Benoit Daloze)
                   ` (9 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: nobu (Nobuyoshi Nakada) @ 2012-07-27  5:19 UTC (permalink / raw)
  To: ruby-core


Issue #6801 has been updated by nobu (Nobuyoshi Nakada).

Description updated


----------------------------------------
Feature #6801: String#~ for a here document
https://bugs.ruby-lang.org/issues/6801#change-28471

Author: merborne (kyo endo)
Status: Open
Priority: Normal
Assignee: 
Category: 
Target version: 


=begin
Let me propose a new method (({String#~})) for a here document.

次のような実装の(({String#~}))を提案します。

    class String
      def ~
        margin = scan(/^ +/).map(&:size).min
        gsub(/^ {#{margin}}/, '')
      end
    end

This is for removing leading margins of a here document.

これはヒアドキュメントにおける先頭マージンを除去するためのものです。

    class ATool
      def self.help
        lines = ~<<-EOS
                  Instruction of `#{self}`
    
        `#{self}` is one of a great tool in the world.
           This helps you a lot on your daily work.
          Your life will be changed with `#{self}`!!
               Everyone knows about `#{self}`.
            So, You can ask them to learn `#{self}`
    
                    Just Use `#{self}`
    
                       from Today!
        EOS
        lines
      end
    end
    
    puts ATool.help
    
    # >>           Instruction of `ATool`
    # >> 
    # >> `ATool` is one of a great tool in the world.
    # >>    This helps you a lot on your daily work.
    # >>   Your life will be changed with `ATool`!!
    # >>        Everyone knows about `ATool`.
    # >>     So, You can ask them to learn `ATool`
    # >> 
    # >>             Just Use `ATool`
    # >> 
    # >>                from Today!

you can put a tilde sign just before the "<<" characters to call String#~, just like putting a minus sign after "<<" to indent the terminator. This is achieved with uniqueness of tilde sign method, which takes the receiver object on the right-hand side.

If you define String#unindent for this purpose, you put `.unindent` after EOS. I think its less elegant than a tilde.

"<<"文字の直前にチルダを置くことで、String#~を呼び出すことができます。これはチルダ記号のメソッドが、そのレシーバオブジェクトを右側に取るという特徴によって実現されます。仮にこの目的のためにString#unindentを定義した場合は、EOSの後に`.unindent`を書くことになりますが、これはチルダに比べると美しくありません。

I understand that this is not general method for string but just for here document. However, I think using a tilde as a method is very restricted because it can't take parameters and is difficult to read the meanings or behavior from the sign. From this, there are few tilde methods within built-in classes of ruby inspite of its uniqness(only for Fixnum, Bignum and Regexp).

so, I think using tilde for the above purpose is the one of the few good chances.

Thank you for your consideration.

このメソッドがStringのための汎用的なものでなく、ヒアドキュメント専用であるということに問題がある点は理解しています。しかし、チルダをメソッドとして使える機会は、それが引数を取れないことと、その記号からはその意味や動作を察することは難しいことから、非常に限られていると想像します。故に、そのユニークさにも拘らず、Rubyの組み込みクラスでの使用例は少しです(Fixnum, BignumおよびRegexpでだけ)。

従って、上記目的でチルダを使うことは、数少ない良い機会であると考えます。

以上、ご検討のほどよろしくお願い致します。

This is based on the following my Japanese blog post.

((<URL:http://melborne.github.com/2012/04/27/ruby-heredoc-without-leading-whitespace/>))
=end



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

^ permalink raw reply	[flat|nested] 12+ messages in thread

* [ruby-core:46807] [ruby-trunk - Feature #6801] String#~ for a here document
  2012-07-27  4:16 [ruby-core:46799] [ruby-trunk - Feature #6801][Open] String#~ for a here document merborne (kyo endo)
  2012-07-27  5:19 ` [ruby-core:46800] [ruby-trunk - Feature #6801] " nobu (Nobuyoshi Nakada)
@ 2012-07-27 10:23 ` Eregon (Benoit Daloze)
  2012-07-27 13:38 ` [ruby-core:46812] " merborne (kyo endo)
                   ` (8 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: Eregon (Benoit Daloze) @ 2012-07-27 10:23 UTC (permalink / raw)
  To: ruby-core


Issue #6801 has been updated by Eregon (Benoit Daloze).


I think the sequence ~<<-EOS becomes very cryptic, and this should be supported in the parser (or at least be integrated into the language). I actually prefer <<-EOS.undent as the intention is clearer.

Maybe something like <<+EOS, which would remove the common indentation?
In your example, it seems fine to have to manually undent the text,
but I think the most common use-case is declaring an heredoc in an indented code.
It does not look nice to have to lose all indentation at that place.
It seems I have similar ideas to what was said in [ruby-core:39851]
(although I don't want explicit indent with '|', I'd still prefer #undent or #~ in that case).

----------------------------------------
Feature #6801: String#~ for a here document
https://bugs.ruby-lang.org/issues/6801#change-28481

Author: merborne (kyo endo)
Status: Open
Priority: Normal
Assignee: 
Category: 
Target version: 


=begin
Let me propose a new method (({String#~})) for a here document.

次のような実装の(({String#~}))を提案します。

    class String
      def ~
        margin = scan(/^ +/).map(&:size).min
        gsub(/^ {#{margin}}/, '')
      end
    end

This is for removing leading margins of a here document.

これはヒアドキュメントにおける先頭マージンを除去するためのものです。

    class ATool
      def self.help
        lines = ~<<-EOS
                  Instruction of `#{self}`
    
        `#{self}` is one of a great tool in the world.
           This helps you a lot on your daily work.
          Your life will be changed with `#{self}`!!
               Everyone knows about `#{self}`.
            So, You can ask them to learn `#{self}`
    
                    Just Use `#{self}`
    
                       from Today!
        EOS
        lines
      end
    end
    
    puts ATool.help
    
    # >>           Instruction of `ATool`
    # >> 
    # >> `ATool` is one of a great tool in the world.
    # >>    This helps you a lot on your daily work.
    # >>   Your life will be changed with `ATool`!!
    # >>        Everyone knows about `ATool`.
    # >>     So, You can ask them to learn `ATool`
    # >> 
    # >>             Just Use `ATool`
    # >> 
    # >>                from Today!

you can put a tilde sign just before the "<<" characters to call String#~, just like putting a minus sign after "<<" to indent the terminator. This is achieved with uniqueness of tilde sign method, which takes the receiver object on the right-hand side.

If you define String#unindent for this purpose, you put `.unindent` after EOS. I think its less elegant than a tilde.

"<<"文字の直前にチルダを置くことで、String#~を呼び出すことができます。これはチルダ記号のメソッドが、そのレシーバオブジェクトを右側に取るという特徴によって実現されます。仮にこの目的のためにString#unindentを定義した場合は、EOSの後に`.unindent`を書くことになりますが、これはチルダに比べると美しくありません。

I understand that this is not general method for string but just for here document. However, I think using a tilde as a method is very restricted because it can't take parameters and is difficult to read the meanings or behavior from the sign. From this, there are few tilde methods within built-in classes of ruby inspite of its uniqness(only for Fixnum, Bignum and Regexp).

so, I think using tilde for the above purpose is the one of the few good chances.

Thank you for your consideration.

このメソッドがStringのための汎用的なものでなく、ヒアドキュメント専用であるということに問題がある点は理解しています。しかし、チルダをメソッドとして使える機会は、それが引数を取れないことと、その記号からはその意味や動作を察することは難しいことから、非常に限られていると想像します。故に、そのユニークさにも拘らず、Rubyの組み込みクラスでの使用例は少しです(Fixnum, BignumおよびRegexpでだけ)。

従って、上記目的でチルダを使うことは、数少ない良い機会であると考えます。

以上、ご検討のほどよろしくお願い致します。

This is based on the following my Japanese blog post.

((<URL:http://melborne.github.com/2012/04/27/ruby-heredoc-without-leading-whitespace/>))
=end



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

^ permalink raw reply	[flat|nested] 12+ messages in thread

* [ruby-core:46812] [ruby-trunk - Feature #6801] String#~ for a here document
  2012-07-27  4:16 [ruby-core:46799] [ruby-trunk - Feature #6801][Open] String#~ for a here document merborne (kyo endo)
  2012-07-27  5:19 ` [ruby-core:46800] [ruby-trunk - Feature #6801] " nobu (Nobuyoshi Nakada)
  2012-07-27 10:23 ` [ruby-core:46807] " Eregon (Benoit Daloze)
@ 2012-07-27 13:38 ` merborne (kyo endo)
  2012-07-27 14:03 ` [ruby-core:46815] " Eregon (Benoit Daloze)
                   ` (7 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: merborne (kyo endo) @ 2012-07-27 13:38 UTC (permalink / raw)
  To: ruby-core


Issue #6801 has been updated by merborne (kyo endo).


Eregon (Benoit Daloze) wrote:
> I think the sequence ~<<-EOS becomes very cryptic, and this should be supported in the parser (or at least be integrated into the language). I actually prefer <<-EOS.undent as the intention is clearer.

Heredoc sytax is already cryptic. so programmers looks it carefully and find the difference between <<-EOS and ~<<-EOS. Yes, this might be supported in the parser. But if so, it will be a big feature or big issue and might be difficult to find the exit. I don't know. On the other hand, I don't prefer Ruby provide <<-EOS.undent style method for this purpose. I prefer it looks a special syntax same as - or <<.

> 
> Maybe something like <<+EOS, which would remove the common indentation?
> In your example, it seems fine to have to manually undent the text,
> but I think the most common use-case is declaring an heredoc in an indented code.

Sorry, I don't understand your point. In the example, the target string is shifted to the left for 4 whitespaces with String#~.

----------------------------------------
Feature #6801: String#~ for a here document
https://bugs.ruby-lang.org/issues/6801#change-28486

Author: merborne (kyo endo)
Status: Open
Priority: Normal
Assignee: 
Category: 
Target version: 


=begin
Let me propose a new method (({String#~})) for a here document.

次のような実装の(({String#~}))を提案します。

    class String
      def ~
        margin = scan(/^ +/).map(&:size).min
        gsub(/^ {#{margin}}/, '')
      end
    end

This is for removing leading margins of a here document.

これはヒアドキュメントにおける先頭マージンを除去するためのものです。

    class ATool
      def self.help
        lines = ~<<-EOS
                  Instruction of `#{self}`
    
        `#{self}` is one of a great tool in the world.
           This helps you a lot on your daily work.
          Your life will be changed with `#{self}`!!
               Everyone knows about `#{self}`.
            So, You can ask them to learn `#{self}`
    
                    Just Use `#{self}`
    
                       from Today!
        EOS
        lines
      end
    end
    
    puts ATool.help
    
    # >>           Instruction of `ATool`
    # >> 
    # >> `ATool` is one of a great tool in the world.
    # >>    This helps you a lot on your daily work.
    # >>   Your life will be changed with `ATool`!!
    # >>        Everyone knows about `ATool`.
    # >>     So, You can ask them to learn `ATool`
    # >> 
    # >>             Just Use `ATool`
    # >> 
    # >>                from Today!

you can put a tilde sign just before the "<<" characters to call String#~, just like putting a minus sign after "<<" to indent the terminator. This is achieved with uniqueness of tilde sign method, which takes the receiver object on the right-hand side.

If you define String#unindent for this purpose, you put `.unindent` after EOS. I think its less elegant than a tilde.

"<<"文字の直前にチルダを置くことで、String#~を呼び出すことができます。これはチルダ記号のメソッドが、そのレシーバオブジェクトを右側に取るという特徴によって実現されます。仮にこの目的のためにString#unindentを定義した場合は、EOSの後に`.unindent`を書くことになりますが、これはチルダに比べると美しくありません。

I understand that this is not general method for string but just for here document. However, I think using a tilde as a method is very restricted because it can't take parameters and is difficult to read the meanings or behavior from the sign. From this, there are few tilde methods within built-in classes of ruby inspite of its uniqness(only for Fixnum, Bignum and Regexp).

so, I think using tilde for the above purpose is the one of the few good chances.

Thank you for your consideration.

このメソッドがStringのための汎用的なものでなく、ヒアドキュメント専用であるということに問題がある点は理解しています。しかし、チルダをメソッドとして使える機会は、それが引数を取れないことと、その記号からはその意味や動作を察することは難しいことから、非常に限られていると想像します。故に、そのユニークさにも拘らず、Rubyの組み込みクラスでの使用例は少しです(Fixnum, BignumおよびRegexpでだけ)。

従って、上記目的でチルダを使うことは、数少ない良い機会であると考えます。

以上、ご検討のほどよろしくお願い致します。

This is based on the following my Japanese blog post.

((<URL:http://melborne.github.com/2012/04/27/ruby-heredoc-without-leading-whitespace/>))
=end



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

^ permalink raw reply	[flat|nested] 12+ messages in thread

* [ruby-core:46815] [ruby-trunk - Feature #6801] String#~ for a here document
  2012-07-27  4:16 [ruby-core:46799] [ruby-trunk - Feature #6801][Open] String#~ for a here document merborne (kyo endo)
                   ` (2 preceding siblings ...)
  2012-07-27 13:38 ` [ruby-core:46812] " merborne (kyo endo)
@ 2012-07-27 14:03 ` Eregon (Benoit Daloze)
  2012-07-27 14:38 ` [ruby-core:46816] " merborne (kyo endo)
                   ` (6 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: Eregon (Benoit Daloze) @ 2012-07-27 14:03 UTC (permalink / raw)
  To: ruby-core


Issue #6801 has been updated by Eregon (Benoit Daloze).


merborne (kyo endo) wrote:
> > 
> > Maybe something like <<+EOS, which would remove the common indentation?
> > In your example, it seems fine to have to manually undent the text,
> > but I think the most common use-case is declaring an heredoc in an indented code.
> 
> Sorry, I don't understand your point. In the example, the target string is shifted to the left for 4 whitespaces with String#~.

I meant your example is probably not the most typical, with its "centered" nature. And I'm fine with having to manually remove the spaces or flush it to the left for such a usage. I would be less fine, with, for example:

module MyApp
  module Commands
    class Show
      def error_message(err)
        <<+EOS
        Error: #{err.class}
        #{err.message}
        EOS
      end
    end
  end
end
(found in [ruby-core:39930])

Sorry, I did not remember http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-core/39959.
You might be right String#~ (or String#undent) to have more chances to ever end.
----------------------------------------
Feature #6801: String#~ for a here document
https://bugs.ruby-lang.org/issues/6801#change-28489

Author: merborne (kyo endo)
Status: Open
Priority: Normal
Assignee: 
Category: 
Target version: 


=begin
Let me propose a new method (({String#~})) for a here document.

次のような実装の(({String#~}))を提案します。

    class String
      def ~
        margin = scan(/^ +/).map(&:size).min
        gsub(/^ {#{margin}}/, '')
      end
    end

This is for removing leading margins of a here document.

これはヒアドキュメントにおける先頭マージンを除去するためのものです。

    class ATool
      def self.help
        lines = ~<<-EOS
                  Instruction of `#{self}`
    
        `#{self}` is one of a great tool in the world.
           This helps you a lot on your daily work.
          Your life will be changed with `#{self}`!!
               Everyone knows about `#{self}`.
            So, You can ask them to learn `#{self}`
    
                    Just Use `#{self}`
    
                       from Today!
        EOS
        lines
      end
    end
    
    puts ATool.help
    
    # >>           Instruction of `ATool`
    # >> 
    # >> `ATool` is one of a great tool in the world.
    # >>    This helps you a lot on your daily work.
    # >>   Your life will be changed with `ATool`!!
    # >>        Everyone knows about `ATool`.
    # >>     So, You can ask them to learn `ATool`
    # >> 
    # >>             Just Use `ATool`
    # >> 
    # >>                from Today!

you can put a tilde sign just before the "<<" characters to call String#~, just like putting a minus sign after "<<" to indent the terminator. This is achieved with uniqueness of tilde sign method, which takes the receiver object on the right-hand side.

If you define String#unindent for this purpose, you put `.unindent` after EOS. I think its less elegant than a tilde.

"<<"文字の直前にチルダを置くことで、String#~を呼び出すことができます。これはチルダ記号のメソッドが、そのレシーバオブジェクトを右側に取るという特徴によって実現されます。仮にこの目的のためにString#unindentを定義した場合は、EOSの後に`.unindent`を書くことになりますが、これはチルダに比べると美しくありません。

I understand that this is not general method for string but just for here document. However, I think using a tilde as a method is very restricted because it can't take parameters and is difficult to read the meanings or behavior from the sign. From this, there are few tilde methods within built-in classes of ruby inspite of its uniqness(only for Fixnum, Bignum and Regexp).

so, I think using tilde for the above purpose is the one of the few good chances.

Thank you for your consideration.

このメソッドがStringのための汎用的なものでなく、ヒアドキュメント専用であるということに問題がある点は理解しています。しかし、チルダをメソッドとして使える機会は、それが引数を取れないことと、その記号からはその意味や動作を察することは難しいことから、非常に限られていると想像します。故に、そのユニークさにも拘らず、Rubyの組み込みクラスでの使用例は少しです(Fixnum, BignumおよびRegexpでだけ)。

従って、上記目的でチルダを使うことは、数少ない良い機会であると考えます。

以上、ご検討のほどよろしくお願い致します。

This is based on the following my Japanese blog post.

((<URL:http://melborne.github.com/2012/04/27/ruby-heredoc-without-leading-whitespace/>))
=end



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

^ permalink raw reply	[flat|nested] 12+ messages in thread

* [ruby-core:46816] [ruby-trunk - Feature #6801] String#~ for a here document
  2012-07-27  4:16 [ruby-core:46799] [ruby-trunk - Feature #6801][Open] String#~ for a here document merborne (kyo endo)
                   ` (3 preceding siblings ...)
  2012-07-27 14:03 ` [ruby-core:46815] " Eregon (Benoit Daloze)
@ 2012-07-27 14:38 ` merborne (kyo endo)
  2012-07-27 16:52 ` [ruby-core:46820] " trans (Thomas Sawyer)
                   ` (5 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: merborne (kyo endo) @ 2012-07-27 14:38 UTC (permalink / raw)
  To: ruby-core


Issue #6801 has been updated by merborne (kyo endo).


Eregon (Benoit Daloze) wrote:
> merborne (kyo endo) wrote:
> > > 
> > > Maybe something like <<+EOS, which would remove the common indentation?
> > > In your example, it seems fine to have to manually undent the text,
> > > but I think the most common use-case is declaring an heredoc in an indented code.
> > 
> > Sorry, I don't understand your point. In the example, the target string is shifted to the left for 4 whitespaces with String#~.
> 
> I meant your example is probably not the most typical, with its "centered" nature. And I'm fine with having to manually remove the spaces or flush it to the left for such a usage. I would be less fine, with, for example:
> 
> module MyApp
>   module Commands
>     class Show
>       def error_message(err)
>         <<+EOS
>         Error: #{err.class}
>         #{err.message}
>         EOS
>       end
>     end
>   end
> end
> (found in [ruby-core:39930])
> 
> Sorry, I did not remember http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-core/39959.
> You might be right String#~ (or String#undent) to have more chances to ever end.

ok. thank you.
----------------------------------------
Feature #6801: String#~ for a here document
https://bugs.ruby-lang.org/issues/6801#change-28490

Author: merborne (kyo endo)
Status: Open
Priority: Normal
Assignee: 
Category: 
Target version: 


=begin
Let me propose a new method (({String#~})) for a here document.

次のような実装の(({String#~}))を提案します。

    class String
      def ~
        margin = scan(/^ +/).map(&:size).min
        gsub(/^ {#{margin}}/, '')
      end
    end

This is for removing leading margins of a here document.

これはヒアドキュメントにおける先頭マージンを除去するためのものです。

    class ATool
      def self.help
        lines = ~<<-EOS
                  Instruction of `#{self}`
    
        `#{self}` is one of a great tool in the world.
           This helps you a lot on your daily work.
          Your life will be changed with `#{self}`!!
               Everyone knows about `#{self}`.
            So, You can ask them to learn `#{self}`
    
                    Just Use `#{self}`
    
                       from Today!
        EOS
        lines
      end
    end
    
    puts ATool.help
    
    # >>           Instruction of `ATool`
    # >> 
    # >> `ATool` is one of a great tool in the world.
    # >>    This helps you a lot on your daily work.
    # >>   Your life will be changed with `ATool`!!
    # >>        Everyone knows about `ATool`.
    # >>     So, You can ask them to learn `ATool`
    # >> 
    # >>             Just Use `ATool`
    # >> 
    # >>                from Today!

you can put a tilde sign just before the "<<" characters to call String#~, just like putting a minus sign after "<<" to indent the terminator. This is achieved with uniqueness of tilde sign method, which takes the receiver object on the right-hand side.

If you define String#unindent for this purpose, you put `.unindent` after EOS. I think its less elegant than a tilde.

"<<"文字の直前にチルダを置くことで、String#~を呼び出すことができます。これはチルダ記号のメソッドが、そのレシーバオブジェクトを右側に取るという特徴によって実現されます。仮にこの目的のためにString#unindentを定義した場合は、EOSの後に`.unindent`を書くことになりますが、これはチルダに比べると美しくありません。

I understand that this is not general method for string but just for here document. However, I think using a tilde as a method is very restricted because it can't take parameters and is difficult to read the meanings or behavior from the sign. From this, there are few tilde methods within built-in classes of ruby inspite of its uniqness(only for Fixnum, Bignum and Regexp).

so, I think using tilde for the above purpose is the one of the few good chances.

Thank you for your consideration.

このメソッドがStringのための汎用的なものでなく、ヒアドキュメント専用であるということに問題がある点は理解しています。しかし、チルダをメソッドとして使える機会は、それが引数を取れないことと、その記号からはその意味や動作を察することは難しいことから、非常に限られていると想像します。故に、そのユニークさにも拘らず、Rubyの組み込みクラスでの使用例は少しです(Fixnum, BignumおよびRegexpでだけ)。

従って、上記目的でチルダを使うことは、数少ない良い機会であると考えます。

以上、ご検討のほどよろしくお願い致します。

This is based on the following my Japanese blog post.

((<URL:http://melborne.github.com/2012/04/27/ruby-heredoc-without-leading-whitespace/>))
=end



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

^ permalink raw reply	[flat|nested] 12+ messages in thread

* [ruby-core:46820] [ruby-trunk - Feature #6801] String#~ for a here document
  2012-07-27  4:16 [ruby-core:46799] [ruby-trunk - Feature #6801][Open] String#~ for a here document merborne (kyo endo)
                   ` (4 preceding siblings ...)
  2012-07-27 14:38 ` [ruby-core:46816] " merborne (kyo endo)
@ 2012-07-27 16:52 ` trans (Thomas Sawyer)
  2012-10-03  9:25 ` [ruby-core:47814] " fahmisetiawand (Fahmi Setiawan)
                   ` (4 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: trans (Thomas Sawyer) @ 2012-07-27 16:52 UTC (permalink / raw)
  To: ruby-core


Issue #6801 has been updated by trans (Thomas Sawyer).


=begin
Alas %L was rejected :(

  str = %L|This
          |  is
          |    margin
          |      controlled.

=end

----------------------------------------
Feature #6801: String#~ for a here document
https://bugs.ruby-lang.org/issues/6801#change-28496

Author: merborne (kyo endo)
Status: Open
Priority: Normal
Assignee: 
Category: 
Target version: 


=begin
Let me propose a new method (({String#~})) for a here document.

次のような実装の(({String#~}))を提案します。

    class String
      def ~
        margin = scan(/^ +/).map(&:size).min
        gsub(/^ {#{margin}}/, '')
      end
    end

This is for removing leading margins of a here document.

これはヒアドキュメントにおける先頭マージンを除去するためのものです。

    class ATool
      def self.help
        lines = ~<<-EOS
                  Instruction of `#{self}`
    
        `#{self}` is one of a great tool in the world.
           This helps you a lot on your daily work.
          Your life will be changed with `#{self}`!!
               Everyone knows about `#{self}`.
            So, You can ask them to learn `#{self}`
    
                    Just Use `#{self}`
    
                       from Today!
        EOS
        lines
      end
    end
    
    puts ATool.help
    
    # >>           Instruction of `ATool`
    # >> 
    # >> `ATool` is one of a great tool in the world.
    # >>    This helps you a lot on your daily work.
    # >>   Your life will be changed with `ATool`!!
    # >>        Everyone knows about `ATool`.
    # >>     So, You can ask them to learn `ATool`
    # >> 
    # >>             Just Use `ATool`
    # >> 
    # >>                from Today!

you can put a tilde sign just before the "<<" characters to call String#~, just like putting a minus sign after "<<" to indent the terminator. This is achieved with uniqueness of tilde sign method, which takes the receiver object on the right-hand side.

If you define String#unindent for this purpose, you put `.unindent` after EOS. I think its less elegant than a tilde.

"<<"文字の直前にチルダを置くことで、String#~を呼び出すことができます。これはチルダ記号のメソッドが、そのレシーバオブジェクトを右側に取るという特徴によって実現されます。仮にこの目的のためにString#unindentを定義した場合は、EOSの後に`.unindent`を書くことになりますが、これはチルダに比べると美しくありません。

I understand that this is not general method for string but just for here document. However, I think using a tilde as a method is very restricted because it can't take parameters and is difficult to read the meanings or behavior from the sign. From this, there are few tilde methods within built-in classes of ruby inspite of its uniqness(only for Fixnum, Bignum and Regexp).

so, I think using tilde for the above purpose is the one of the few good chances.

Thank you for your consideration.

このメソッドがStringのための汎用的なものでなく、ヒアドキュメント専用であるということに問題がある点は理解しています。しかし、チルダをメソッドとして使える機会は、それが引数を取れないことと、その記号からはその意味や動作を察することは難しいことから、非常に限られていると想像します。故に、そのユニークさにも拘らず、Rubyの組み込みクラスでの使用例は少しです(Fixnum, BignumおよびRegexpでだけ)。

従って、上記目的でチルダを使うことは、数少ない良い機会であると考えます。

以上、ご検討のほどよろしくお願い致します。

This is based on the following my Japanese blog post.

((<URL:http://melborne.github.com/2012/04/27/ruby-heredoc-without-leading-whitespace/>))
=end



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

^ permalink raw reply	[flat|nested] 12+ messages in thread

* [ruby-core:47814] [ruby-trunk - Feature #6801] String#~ for a here document
  2012-07-27  4:16 [ruby-core:46799] [ruby-trunk - Feature #6801][Open] String#~ for a here document merborne (kyo endo)
                   ` (5 preceding siblings ...)
  2012-07-27 16:52 ` [ruby-core:46820] " trans (Thomas Sawyer)
@ 2012-10-03  9:25 ` fahmisetiawand (Fahmi Setiawan)
  2012-11-24  0:12 ` [ruby-core:49925] [ruby-trunk - Feature #6801][Assigned] " mame (Yusuke Endoh)
                   ` (3 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: fahmisetiawand (Fahmi Setiawan) @ 2012-10-03  9:25 UTC (permalink / raw)
  To: ruby-core


Issue #6801 has been updated by fahmisetiawand (Fahmi Setiawan).


http://alkian.blogspot.com/2012/09/cara-menyembuhkan-asam-urat-dan-kolestrol-secara-alami.html
http://alkian.blogspot.com/2012/09/keretamini-keretamall-komediputar-ya-keretaminikucom.html
http://alkian.blogspot.com/2012/10/kata-kata-mutiara-motivasi-terbaru-2012.html
http://alkian.blogspot.com/2012/08/personil-coboy-junior.html
http://alkian.blogspot.com/2012/10/hasil-dan-klasemen-liga-champions.html
----------------------------------------
Feature #6801: String#~ for a here document
https://bugs.ruby-lang.org/issues/6801#change-29970

Author: merborne (kyo endo)
Status: Open
Priority: Normal
Assignee: 
Category: 
Target version: 


=begin
Let me propose a new method (({String#~})) for a here document.

次のような実装の(({String#~}))を提案します。

    class String
      def ~
        margin = scan(/^ +/).map(&:size).min
        gsub(/^ {#{margin}}/, '')
      end
    end

This is for removing leading margins of a here document.

これはヒアドキュメントにおける先頭マージンを除去するためのものです。

    class ATool
      def self.help
        lines = ~<<-EOS
                  Instruction of `#{self}`
    
        `#{self}` is one of a great tool in the world.
           This helps you a lot on your daily work.
          Your life will be changed with `#{self}`!!
               Everyone knows about `#{self}`.
            So, You can ask them to learn `#{self}`
    
                    Just Use `#{self}`
    
                       from Today!
        EOS
        lines
      end
    end
    
    puts ATool.help
    
    # >>           Instruction of `ATool`
    # >> 
    # >> `ATool` is one of a great tool in the world.
    # >>    This helps you a lot on your daily work.
    # >>   Your life will be changed with `ATool`!!
    # >>        Everyone knows about `ATool`.
    # >>     So, You can ask them to learn `ATool`
    # >> 
    # >>             Just Use `ATool`
    # >> 
    # >>                from Today!

you can put a tilde sign just before the "<<" characters to call String#~, just like putting a minus sign after "<<" to indent the terminator. This is achieved with uniqueness of tilde sign method, which takes the receiver object on the right-hand side.

If you define String#unindent for this purpose, you put `.unindent` after EOS. I think its less elegant than a tilde.

"<<"文字の直前にチルダを置くことで、String#~を呼び出すことができます。これはチルダ記号のメソッドが、そのレシーバオブジェクトを右側に取るという特徴によって実現されます。仮にこの目的のためにString#unindentを定義した場合は、EOSの後に`.unindent`を書くことになりますが、これはチルダに比べると美しくありません。

I understand that this is not general method for string but just for here document. However, I think using a tilde as a method is very restricted because it can't take parameters and is difficult to read the meanings or behavior from the sign. From this, there are few tilde methods within built-in classes of ruby inspite of its uniqness(only for Fixnum, Bignum and Regexp).

so, I think using tilde for the above purpose is the one of the few good chances.

Thank you for your consideration.

このメソッドがStringのための汎用的なものでなく、ヒアドキュメント専用であるということに問題がある点は理解しています。しかし、チルダをメソッドとして使える機会は、それが引数を取れないことと、その記号からはその意味や動作を察することは難しいことから、非常に限られていると想像します。故に、そのユニークさにも拘らず、Rubyの組み込みクラスでの使用例は少しです(Fixnum, BignumおよびRegexpでだけ)。

従って、上記目的でチルダを使うことは、数少ない良い機会であると考えます。

以上、ご検討のほどよろしくお願い致します。

This is based on the following my Japanese blog post.

((<URL:http://melborne.github.com/2012/04/27/ruby-heredoc-without-leading-whitespace/>))
=end



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

^ permalink raw reply	[flat|nested] 12+ messages in thread

* [ruby-core:49925] [ruby-trunk - Feature #6801][Assigned] String#~ for a here document
  2012-07-27  4:16 [ruby-core:46799] [ruby-trunk - Feature #6801][Open] String#~ for a here document merborne (kyo endo)
                   ` (6 preceding siblings ...)
  2012-10-03  9:25 ` [ruby-core:47814] " fahmisetiawand (Fahmi Setiawan)
@ 2012-11-24  0:12 ` mame (Yusuke Endoh)
  2012-11-24  3:12 ` [ruby-core:49988] [ruby-trunk - Feature #6801] " trans (Thomas Sawyer)
                   ` (2 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: mame (Yusuke Endoh) @ 2012-11-24  0:12 UTC (permalink / raw)
  To: ruby-core


Issue #6801 has been updated by mame (Yusuke Endoh).

Status changed from Open to Assigned
Assignee set to matz (Yukihiro Matsumoto)
Target version set to Next Major


----------------------------------------
Feature #6801: String#~ for a here document
https://bugs.ruby-lang.org/issues/6801#change-33684

Author: merborne (kyo endo)
Status: Assigned
Priority: Normal
Assignee: matz (Yukihiro Matsumoto)
Category: 
Target version: Next Major


=begin
Let me propose a new method (({String#~})) for a here document.

次のような実装の(({String#~}))を提案します。

    class String
      def ~
        margin = scan(/^ +/).map(&:size).min
        gsub(/^ {#{margin}}/, '')
      end
    end

This is for removing leading margins of a here document.

これはヒアドキュメントにおける先頭マージンを除去するためのものです。

    class ATool
      def self.help
        lines = ~<<-EOS
                  Instruction of `#{self}`
    
        `#{self}` is one of a great tool in the world.
           This helps you a lot on your daily work.
          Your life will be changed with `#{self}`!!
               Everyone knows about `#{self}`.
            So, You can ask them to learn `#{self}`
    
                    Just Use `#{self}`
    
                       from Today!
        EOS
        lines
      end
    end
    
    puts ATool.help
    
    # >>           Instruction of `ATool`
    # >> 
    # >> `ATool` is one of a great tool in the world.
    # >>    This helps you a lot on your daily work.
    # >>   Your life will be changed with `ATool`!!
    # >>        Everyone knows about `ATool`.
    # >>     So, You can ask them to learn `ATool`
    # >> 
    # >>             Just Use `ATool`
    # >> 
    # >>                from Today!

you can put a tilde sign just before the "<<" characters to call String#~, just like putting a minus sign after "<<" to indent the terminator. This is achieved with uniqueness of tilde sign method, which takes the receiver object on the right-hand side.

If you define String#unindent for this purpose, you put `.unindent` after EOS. I think its less elegant than a tilde.

"<<"文字の直前にチルダを置くことで、String#~を呼び出すことができます。これはチルダ記号のメソッドが、そのレシーバオブジェクトを右側に取るという特徴によって実現されます。仮にこの目的のためにString#unindentを定義した場合は、EOSの後に`.unindent`を書くことになりますが、これはチルダに比べると美しくありません。

I understand that this is not general method for string but just for here document. However, I think using a tilde as a method is very restricted because it can't take parameters and is difficult to read the meanings or behavior from the sign. From this, there are few tilde methods within built-in classes of ruby inspite of its uniqness(only for Fixnum, Bignum and Regexp).

so, I think using tilde for the above purpose is the one of the few good chances.

Thank you for your consideration.

このメソッドがStringのための汎用的なものでなく、ヒアドキュメント専用であるということに問題がある点は理解しています。しかし、チルダをメソッドとして使える機会は、それが引数を取れないことと、その記号からはその意味や動作を察することは難しいことから、非常に限られていると想像します。故に、そのユニークさにも拘らず、Rubyの組み込みクラスでの使用例は少しです(Fixnum, BignumおよびRegexpでだけ)。

従って、上記目的でチルダを使うことは、数少ない良い機会であると考えます。

以上、ご検討のほどよろしくお願い致します。

This is based on the following my Japanese blog post.

((<URL:http://melborne.github.com/2012/04/27/ruby-heredoc-without-leading-whitespace/>))
=end



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

^ permalink raw reply	[flat|nested] 12+ messages in thread

* [ruby-core:49988] [ruby-trunk - Feature #6801] String#~ for a here document
  2012-07-27  4:16 [ruby-core:46799] [ruby-trunk - Feature #6801][Open] String#~ for a here document merborne (kyo endo)
                   ` (7 preceding siblings ...)
  2012-11-24  0:12 ` [ruby-core:49925] [ruby-trunk - Feature #6801][Assigned] " mame (Yusuke Endoh)
@ 2012-11-24  3:12 ` trans (Thomas Sawyer)
  2019-01-16 17:14 ` [ruby-core:91130] [Ruby trunk Feature#6801] " justin
  2019-01-16 20:49 ` [ruby-core:91132] " eregontp
  10 siblings, 0 replies; 12+ messages in thread
From: trans (Thomas Sawyer) @ 2012-11-24  3:12 UTC (permalink / raw)
  To: ruby-core


Issue #6801 has been updated by trans (Thomas Sawyer).


=begin
This is really an area in which Ruby is sorely missing some needed String methods. Some of the most commonly used methods in Ruby Facets deal with indention, mainly:

  # Preserves relative tabbing such that the line with the least amount 
  # of white space ends up with `n` number of spaces before non-space and
  # all other lines move relative to it.

  def tab(n)
    str = gsub("\t", "  ")  # option?

    min = []
    str.each_line do |line|
      next if line.strip.empty?
      min << line.index(/\S/)
    end
    min = min.min

    str.indent(n - min)
  end

  # Preserves relative tabbing, such that the first non-empty line ends up with
  # `n` number of spaces before non-space, and all subsequent lines move relative
  # to the first.
  #
  # CREDIT: Gavin Sinclair

  def tabto(n)
    if self =~ /^( *)\S/
      indent(n - $1.length)
    else
      self
    end
  end

  # Indent left or right by `n` spaces, or `n` number of `c` string.
  #
  # CREDIT: Gavin Sinclair, Trans, Tyler Rick

  def indent(n, c=' ')
    if n >= 0
      gsub(/^/, c * n)
    else
      gsub(/^#{Regexp.escape(c)}{0,#{-n}}/, "")
    end
  end

  # Equivalent to String#indent, but modifies the receiver in place.

  def indent!(n, c=' ')
    replace(indent(n,c))
  end

  # Remove excessive indentation. Useful for multi-line strings embeded in
  # already indented code.
  #
  #   <<-END.unindent
  #       ohaie
  #         wurld
  #   END
  #
  # Outputs ...
  #
  #   ohaie
  #     wurld
  #
  # Instead of ...
  #
  #       ohaie
  #         wurld
  #
  # CREDIT: Noah Gibbs, mynyml

  def unindent(size=nil)
    if size
      indent(-size)
    else
      char = ' '
      self.scan(/^[\ \t]*\S/) do |m|
        if size.nil? || m.size < size
          size = m.size
          char = m[0...-1]
        end
      end
      size -= 1
      indent(-size, char)
    end
  end

  # Equivalent to String#unindent, but modifies the receiver in place.
  #
  # CREDIT: mynyml

  def unindent!
    self.replace(self.unindent)
  end

While I understand the intention of using (({~})) so as to make it part of HERE document syntax, I don't think it outweighs the advantages of having more flexible methods such as these.

=end
----------------------------------------
Feature #6801: String#~ for a here document
https://bugs.ruby-lang.org/issues/6801#change-33757

Author: merborne (kyo endo)
Status: Assigned
Priority: Normal
Assignee: matz (Yukihiro Matsumoto)
Category: 
Target version: Next Major


=begin
Let me propose a new method (({String#~})) for a here document.

次のような実装の(({String#~}))を提案します。

    class String
      def ~
        margin = scan(/^ +/).map(&:size).min
        gsub(/^ {#{margin}}/, '')
      end
    end

This is for removing leading margins of a here document.

これはヒアドキュメントにおける先頭マージンを除去するためのものです。

    class ATool
      def self.help
        lines = ~<<-EOS
                  Instruction of `#{self}`
    
        `#{self}` is one of a great tool in the world.
           This helps you a lot on your daily work.
          Your life will be changed with `#{self}`!!
               Everyone knows about `#{self}`.
            So, You can ask them to learn `#{self}`
    
                    Just Use `#{self}`
    
                       from Today!
        EOS
        lines
      end
    end
    
    puts ATool.help
    
    # >>           Instruction of `ATool`
    # >> 
    # >> `ATool` is one of a great tool in the world.
    # >>    This helps you a lot on your daily work.
    # >>   Your life will be changed with `ATool`!!
    # >>        Everyone knows about `ATool`.
    # >>     So, You can ask them to learn `ATool`
    # >> 
    # >>             Just Use `ATool`
    # >> 
    # >>                from Today!

you can put a tilde sign just before the "<<" characters to call String#~, just like putting a minus sign after "<<" to indent the terminator. This is achieved with uniqueness of tilde sign method, which takes the receiver object on the right-hand side.

If you define String#unindent for this purpose, you put `.unindent` after EOS. I think its less elegant than a tilde.

"<<"文字の直前にチルダを置くことで、String#~を呼び出すことができます。これはチルダ記号のメソッドが、そのレシーバオブジェクトを右側に取るという特徴によって実現されます。仮にこの目的のためにString#unindentを定義した場合は、EOSの後に`.unindent`を書くことになりますが、これはチルダに比べると美しくありません。

I understand that this is not general method for string but just for here document. However, I think using a tilde as a method is very restricted because it can't take parameters and is difficult to read the meanings or behavior from the sign. From this, there are few tilde methods within built-in classes of ruby inspite of its uniqness(only for Fixnum, Bignum and Regexp).

so, I think using tilde for the above purpose is the one of the few good chances.

Thank you for your consideration.

このメソッドがStringのための汎用的なものでなく、ヒアドキュメント専用であるということに問題がある点は理解しています。しかし、チルダをメソッドとして使える機会は、それが引数を取れないことと、その記号からはその意味や動作を察することは難しいことから、非常に限られていると想像します。故に、そのユニークさにも拘らず、Rubyの組み込みクラスでの使用例は少しです(Fixnum, BignumおよびRegexpでだけ)。

従って、上記目的でチルダを使うことは、数少ない良い機会であると考えます。

以上、ご検討のほどよろしくお願い致します。

This is based on the following my Japanese blog post.

((<URL:http://melborne.github.com/2012/04/27/ruby-heredoc-without-leading-whitespace/>))
=end



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

^ permalink raw reply	[flat|nested] 12+ messages in thread

* [ruby-core:91130] [Ruby trunk Feature#6801] String#~ for a here document
  2012-07-27  4:16 [ruby-core:46799] [ruby-trunk - Feature #6801][Open] String#~ for a here document merborne (kyo endo)
                   ` (8 preceding siblings ...)
  2012-11-24  3:12 ` [ruby-core:49988] [ruby-trunk - Feature #6801] " trans (Thomas Sawyer)
@ 2019-01-16 17:14 ` justin
  2019-01-16 20:49 ` [ruby-core:91132] " eregontp
  10 siblings, 0 replies; 12+ messages in thread
From: justin @ 2019-01-16 17:14 UTC (permalink / raw)
  To: ruby-core

Issue #6801 has been updated by jsc (Justin Collins).


Since this exact behavior was added as "indented here document" with `<<~` in Ruby 2.3.0 (discussed in #9098), I believe this issue can be closed out.

----------------------------------------
Feature #6801: String#~ for a here document
https://bugs.ruby-lang.org/issues/6801#change-76361

* Author: merborne (kyo endo)
* Status: Assigned
* Priority: Normal
* Assignee: matz (Yukihiro Matsumoto)
* Target version: Next Major
----------------------------------------
=begin
Let me propose a new method (({String#~})) for a here document.

次のような実装の(({String#~}))を提案します。

    class String
      def ~
        margin = scan(/^ +/).map(&:size).min
        gsub(/^ {#{margin}}/, '')
      end
    end

This is for removing leading margins of a here document.

これはヒアドキュメントにおける先頭マージンを除去するためのものです。

    class ATool
      def self.help
        lines = ~<<-EOS
                  Instruction of `#{self}`
    
        `#{self}` is one of a great tool in the world.
           This helps you a lot on your daily work.
          Your life will be changed with `#{self}`!!
               Everyone knows about `#{self}`.
            So, You can ask them to learn `#{self}`
    
                    Just Use `#{self}`
    
                       from Today!
        EOS
        lines
      end
    end
    
    puts ATool.help
    
    # >>           Instruction of `ATool`
    # >> 
    # >> `ATool` is one of a great tool in the world.
    # >>    This helps you a lot on your daily work.
    # >>   Your life will be changed with `ATool`!!
    # >>        Everyone knows about `ATool`.
    # >>     So, You can ask them to learn `ATool`
    # >> 
    # >>             Just Use `ATool`
    # >> 
    # >>                from Today!

you can put a tilde sign just before the "<<" characters to call String#~, just like putting a minus sign after "<<" to indent the terminator. This is achieved with uniqueness of tilde sign method, which takes the receiver object on the right-hand side.

If you define String#unindent for this purpose, you put `.unindent` after EOS. I think its less elegant than a tilde.

"<<"文字の直前にチルダを置くことで、String#~を呼び出すことができます。これはチルダ記号のメソッドが、そのレシーバオブジェクトを右側に取るという特徴によって実現されます。仮にこの目的のためにString#unindentを定義した場合は、EOSの後に`.unindent`を書くことになりますが、これはチルダに比べると美しくありません。

I understand that this is not general method for string but just for here document. However, I think using a tilde as a method is very restricted because it can't take parameters and is difficult to read the meanings or behavior from the sign. From this, there are few tilde methods within built-in classes of ruby inspite of its uniqness(only for Fixnum, Bignum and Regexp).

so, I think using tilde for the above purpose is the one of the few good chances.

Thank you for your consideration.

このメソッドがStringのための汎用的なものでなく、ヒアドキュメント専用であるということに問題がある点は理解しています。しかし、チルダをメソッドとして使える機会は、それが引数を取れないことと、その記号からはその意味や動作を察することは難しいことから、非常に限られていると想像します。故に、そのユニークさにも拘らず、Rubyの組み込みクラスでの使用例は少しです(Fixnum, BignumおよびRegexpでだけ)。

従って、上記目的でチルダを使うことは、数少ない良い機会であると考えます。

以上、ご検討のほどよろしくお願い致します。

This is based on the following my Japanese blog post.

((<URL:http://melborne.github.com/2012/04/27/ruby-heredoc-without-leading-whitespace/>))
=end




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

^ permalink raw reply	[flat|nested] 12+ messages in thread

* [ruby-core:91132] [Ruby trunk Feature#6801] String#~ for a here document
  2012-07-27  4:16 [ruby-core:46799] [ruby-trunk - Feature #6801][Open] String#~ for a here document merborne (kyo endo)
                   ` (9 preceding siblings ...)
  2019-01-16 17:14 ` [ruby-core:91130] [Ruby trunk Feature#6801] " justin
@ 2019-01-16 20:49 ` eregontp
  10 siblings, 0 replies; 12+ messages in thread
From: eregontp @ 2019-01-16 20:49 UTC (permalink / raw)
  To: ruby-core

Issue #6801 has been updated by Eregon (Benoit Daloze).

Target version deleted (Next Major)
Status changed from Assigned to Rejected

Indeed.

----------------------------------------
Feature #6801: String#~ for a here document
https://bugs.ruby-lang.org/issues/6801#change-76363

* Author: merborne (kyo endo)
* Status: Rejected
* Priority: Normal
* Assignee: matz (Yukihiro Matsumoto)
* Target version: 
----------------------------------------
=begin
Let me propose a new method (({String#~})) for a here document.

次のような実装の(({String#~}))を提案します。

    class String
      def ~
        margin = scan(/^ +/).map(&:size).min
        gsub(/^ {#{margin}}/, '')
      end
    end

This is for removing leading margins of a here document.

これはヒアドキュメントにおける先頭マージンを除去するためのものです。

    class ATool
      def self.help
        lines = ~<<-EOS
                  Instruction of `#{self}`
    
        `#{self}` is one of a great tool in the world.
           This helps you a lot on your daily work.
          Your life will be changed with `#{self}`!!
               Everyone knows about `#{self}`.
            So, You can ask them to learn `#{self}`
    
                    Just Use `#{self}`
    
                       from Today!
        EOS
        lines
      end
    end
    
    puts ATool.help
    
    # >>           Instruction of `ATool`
    # >> 
    # >> `ATool` is one of a great tool in the world.
    # >>    This helps you a lot on your daily work.
    # >>   Your life will be changed with `ATool`!!
    # >>        Everyone knows about `ATool`.
    # >>     So, You can ask them to learn `ATool`
    # >> 
    # >>             Just Use `ATool`
    # >> 
    # >>                from Today!

you can put a tilde sign just before the "<<" characters to call String#~, just like putting a minus sign after "<<" to indent the terminator. This is achieved with uniqueness of tilde sign method, which takes the receiver object on the right-hand side.

If you define String#unindent for this purpose, you put `.unindent` after EOS. I think its less elegant than a tilde.

"<<"文字の直前にチルダを置くことで、String#~を呼び出すことができます。これはチルダ記号のメソッドが、そのレシーバオブジェクトを右側に取るという特徴によって実現されます。仮にこの目的のためにString#unindentを定義した場合は、EOSの後に`.unindent`を書くことになりますが、これはチルダに比べると美しくありません。

I understand that this is not general method for string but just for here document. However, I think using a tilde as a method is very restricted because it can't take parameters and is difficult to read the meanings or behavior from the sign. From this, there are few tilde methods within built-in classes of ruby inspite of its uniqness(only for Fixnum, Bignum and Regexp).

so, I think using tilde for the above purpose is the one of the few good chances.

Thank you for your consideration.

このメソッドがStringのための汎用的なものでなく、ヒアドキュメント専用であるということに問題がある点は理解しています。しかし、チルダをメソッドとして使える機会は、それが引数を取れないことと、その記号からはその意味や動作を察することは難しいことから、非常に限られていると想像します。故に、そのユニークさにも拘らず、Rubyの組み込みクラスでの使用例は少しです(Fixnum, BignumおよびRegexpでだけ)。

従って、上記目的でチルダを使うことは、数少ない良い機会であると考えます。

以上、ご検討のほどよろしくお願い致します。

This is based on the following my Japanese blog post.

((<URL:http://melborne.github.com/2012/04/27/ruby-heredoc-without-leading-whitespace/>))
=end




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

^ permalink raw reply	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2019-01-16 20:49 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-07-27  4:16 [ruby-core:46799] [ruby-trunk - Feature #6801][Open] String#~ for a here document merborne (kyo endo)
2012-07-27  5:19 ` [ruby-core:46800] [ruby-trunk - Feature #6801] " nobu (Nobuyoshi Nakada)
2012-07-27 10:23 ` [ruby-core:46807] " Eregon (Benoit Daloze)
2012-07-27 13:38 ` [ruby-core:46812] " merborne (kyo endo)
2012-07-27 14:03 ` [ruby-core:46815] " Eregon (Benoit Daloze)
2012-07-27 14:38 ` [ruby-core:46816] " merborne (kyo endo)
2012-07-27 16:52 ` [ruby-core:46820] " trans (Thomas Sawyer)
2012-10-03  9:25 ` [ruby-core:47814] " fahmisetiawand (Fahmi Setiawan)
2012-11-24  0:12 ` [ruby-core:49925] [ruby-trunk - Feature #6801][Assigned] " mame (Yusuke Endoh)
2012-11-24  3:12 ` [ruby-core:49988] [ruby-trunk - Feature #6801] " trans (Thomas Sawyer)
2019-01-16 17:14 ` [ruby-core:91130] [Ruby trunk Feature#6801] " justin
2019-01-16 20:49 ` [ruby-core:91132] " eregontp

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).