From 4a14d54eb520f9776710102bfec740467b549745 Mon Sep 17 00:00:00 2001 From: Ilya Vorontsov Date: Thu, 5 Sep 2019 11:06:51 +0300 Subject: [ruby/ru] [ruby/en] added notes about postfix-if and about --- ruby.html.markdown | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'ruby.html.markdown') diff --git a/ruby.html.markdown b/ruby.html.markdown index 2595d1d5..d77672ab 100644 --- a/ruby.html.markdown +++ b/ruby.html.markdown @@ -247,6 +247,14 @@ else 'else, also optional' end +# If a condition controls invokation of a single statement rather than a block of code +# you can use postfix-if notation +warnings = ['Patronimic is missing', 'Address too short'] +puts("Some warnings occurred:\n" + warnings.join("\n")) if !warnings.empty? + +# Rephrase condition if `unless` sounds better than `if` +puts("Some warnings occurred:\n" + warnings.join("\n")) unless warnings.empty? + # Loops # In Ruby, traditional `for` loops aren't very common. Instead, these # basic loops are implemented using enumerable, which hinges on `each`. -- cgit v1.2.3 From d0d0fe4995d5be0bc7d1bc749c959468dec2f35c Mon Sep 17 00:00:00 2001 From: Chris Zimmerman Date: Tue, 1 Oct 2019 16:45:47 -0400 Subject: en/ruby - Adds documentation for multiline comments --- ruby.html.markdown | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'ruby.html.markdown') diff --git a/ruby.html.markdown b/ruby.html.markdown index d77672ab..b36d1526 100644 --- a/ruby.html.markdown +++ b/ruby.html.markdown @@ -23,6 +23,15 @@ contributors: ```ruby # This is a comment +=begin +This is a multi-line comment. +The beginning line must start with "=begin" +and the ending line must start with "=end". + +You can do this, or start each line in +a multi-line comment with the # character. +=end + # In Ruby, (almost) everything is an object. # This includes numbers... 3.class #=> Integer -- cgit v1.2.3 From 03c06ac1bc8dc2da43d6ff29cade0d235103033c Mon Sep 17 00:00:00 2001 From: Alex Mendes da Costa Date: Mon, 9 Dec 2019 09:19:36 -0800 Subject: Fix typo in ruby.html.markdown "arugments" => "arguments" --- ruby.html.markdown | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'ruby.html.markdown') diff --git a/ruby.html.markdown b/ruby.html.markdown index d77672ab..f437adcf 100644 --- a/ruby.html.markdown +++ b/ruby.html.markdown @@ -410,7 +410,7 @@ def guests(&block) end # The 'call' method on the Proc is similar to calling 'yield' when a block is -# present. The arguments passed to 'call' will be forwarded to the block as arugments. +# present. The arguments passed to 'call' will be forwarded to the block as arguments. guests { |n| "You have #{n} guests." } # => "You have 4 guests." -- cgit v1.2.3 From 2eb57cb02376df701e80d2692deab5809214171a Mon Sep 17 00:00:00 2001 From: Barton Stanley Date: Fri, 31 Jan 2020 13:04:15 -0600 Subject: Change "invokation" to "invocation" --- ruby.html.markdown | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'ruby.html.markdown') diff --git a/ruby.html.markdown b/ruby.html.markdown index 3fc2ed2d..376f4a47 100644 --- a/ruby.html.markdown +++ b/ruby.html.markdown @@ -256,7 +256,7 @@ else 'else, also optional' end -# If a condition controls invokation of a single statement rather than a block of code +# If a condition controls invocation of a single statement rather than a block of code # you can use postfix-if notation warnings = ['Patronimic is missing', 'Address too short'] puts("Some warnings occurred:\n" + warnings.join("\n")) if !warnings.empty? -- cgit v1.2.3 From c6804101b9f60c9083f88b24a1dfa5b91443fc94 Mon Sep 17 00:00:00 2001 From: Jake Haber Date: Tue, 21 Apr 2020 07:33:51 -0500 Subject: Add Ruby shorthand block syntax examples --- ruby.html.markdown | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'ruby.html.markdown') diff --git a/ruby.html.markdown b/ruby.html.markdown index 376f4a47..d21c727f 100644 --- a/ruby.html.markdown +++ b/ruby.html.markdown @@ -430,6 +430,16 @@ def guests(*array) array.each { |guest| puts guest } end +# There is also the shorthand block syntax. It's most useful when you need +# to call a simple method on all array items. +upcased = ['Watch', 'these', 'words', 'get', 'upcased'].map(&:upcase) +puts upcased +#=> ["WATCH", "THESE", "WORDS", "GET", "UPCASED"] + +sum = [1, 2, 3, 4, 5].reduce(&:+) +puts sum +#=> 15 + # Destructuring # Ruby will automatically destructure arrays on assignment to multiple variables. -- cgit v1.2.3 From a67f4663eb1b477cb50da9986fc5da945864ebab Mon Sep 17 00:00:00 2001 From: Claudio Secco Date: Sat, 2 May 2020 13:03:36 -0300 Subject: include %w option --- ruby.html.markdown | 3 +++ 1 file changed, 3 insertions(+) (limited to 'ruby.html.markdown') diff --git a/ruby.html.markdown b/ruby.html.markdown index 376f4a47..97f7a516 100644 --- a/ruby.html.markdown +++ b/ruby.html.markdown @@ -181,6 +181,9 @@ array = [1, 2, 3, 4, 5] #=> [1, 2, 3, 4, 5] # Arrays can contain different types of items. [1, 'hello', false] #=> [1, "hello", false] +# You might prefer %w instead of quotes +%w[foo bar baz] #=> ["foo", "bar", "baz"] + # Arrays can be indexed. # From the front... array[0] #=> 1 -- cgit v1.2.3 From d9ee9ce3903f078c68d796464c70c463c1bf133b Mon Sep 17 00:00:00 2001 From: Claudio Secco Date: Sat, 2 May 2020 16:09:41 -0300 Subject: [ruby/en] add .map($:method) sintax in blocks context --- ruby.html.markdown | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'ruby.html.markdown') diff --git a/ruby.html.markdown b/ruby.html.markdown index 97f7a516..3111d09b 100644 --- a/ruby.html.markdown +++ b/ruby.html.markdown @@ -327,6 +327,11 @@ puts doubled puts array #=> [1,2,3,4,5] +# another useful sintax is .map(&:method) +a = ["FOO", "BAR", "BAZ"] +a.map { |s| s.downcase } #=> ["foo", "bar", "baz"] +a.map(&:downcase) #=> ["foo", "bar", "baz"] + # Case construct grade = 'B' -- cgit v1.2.3 From 20a468579ac87bd56f1f9e95a7f065e3519522af Mon Sep 17 00:00:00 2001 From: Claudio Secco <41170119+claudiosecco@users.noreply.github.com> Date: Tue, 7 Jul 2020 20:27:34 -0300 Subject: [ruby/en] fix typo --- ruby.html.markdown | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'ruby.html.markdown') diff --git a/ruby.html.markdown b/ruby.html.markdown index 3111d09b..0e35a7ec 100644 --- a/ruby.html.markdown +++ b/ruby.html.markdown @@ -327,7 +327,7 @@ puts doubled puts array #=> [1,2,3,4,5] -# another useful sintax is .map(&:method) +# another useful syntax is .map(&:method) a = ["FOO", "BAR", "BAZ"] a.map { |s| s.downcase } #=> ["foo", "bar", "baz"] a.map(&:downcase) #=> ["foo", "bar", "baz"] -- cgit v1.2.3