[#405207] Does `self` and `scope(local)` operate parallels? — "Kumar R." <lists@...>

I am heavily confused with the topic when thinking `self` and `local

21 messages 2013/03/01
[#405211] Re: Does `self` and `scope(local)` operate parallels? — "Kumar R." <lists@...> 2013/03/01

Just to help experts out there I am clearing my statement once again

[#405242] Confusion in instance method calls of super class from subclass — "Kumar R." <lists@...>

I was just playing to see the instance method calls from the subclass

16 messages 2013/03/02
[#405252] Re: Confusion in instance method calls of super class from subclass — Hans Mackowiak <lists@...> 2013/03/03

YOU DID NOT READ WHAT I WAS WRITTEN:

[#405250] Extending Ruby. Little help or guidance if you are willing! — Cliff Rosson <cliff.rosson@...>

Hi Folk,

21 messages 2013/03/03
[#405393] Re: Extending Ruby. Little help or guidance if you are willing! — nannasin smith <lists@...> 2013/03/06

I've tried to do some reading but some of this is a bit over my head.

[#405549] Re: Extending Ruby. Little help or guidance if you are willing! — Cliff Rosson <cliff.rosson@...> 2013/03/10

Haven't been able to touch this in a week but I had a few minutes to look

[#405550] Re: Extending Ruby. Little help or guidance if you are willing! — Bartosz Dziewoński <matma.rex@...> 2013/03/10

On Sun, 10 Mar 2013 04:41:32 +0100, Cliff Rosson <cliff.rosson@gmail.com> wrote:

[#405600] Re: Extending Ruby. Little help or guidance if you are willing! — Cliff Rosson <cliff.rosson@...> 2013/03/11

Got ya. So it doesn't really matter if I convert things to ID and compare

[#405271] Confusion with Ruby's "case/when" block statement — "Kumar R." <lists@...>

Ruby uses `===` operator on the `case/when` type execution style.Now It

13 messages 2013/03/03

[#405310] How `next` works in ruby with `unless` ? — "Kumar R." <lists@...>

The `next` statement is used to skip a part of the loop and continue

25 messages 2013/03/04
[#405311] Re: How `next` works in ruby with `unless` ? — Joel Pearson <lists@...> 2013/03/04

Learn what semicolons do in Ruby.

[#405312] Re: How `next` works in ruby with `unless` ? — Matthew Kerwin <matthew@...> 2013/03/04

What Joel said.

[#405313] Re: How `next` works in ruby with `unless` ? — "Kumar R." <lists@...> 2013/03/04

Matthew Kerwin wrote in post #1100097:

[#405323] YourLanguageSucks — Kiswono Prayogo <kiswono@...>

Hi, i found this link.. https://wiki.theory.org/YourLanguageSucks

10 messages 2013/03/05

[#405376] When can one call themselves a “Rubyist”? — Rafal Chmiel <lists@...>

I was wondering what that term even meant. Is it something to do with

10 messages 2013/03/05

[#405400] Bignum-Fixnum-Numeric confusion — Pritam Dey <lists@...>

Hi,

13 messages 2013/03/06

[#405444] Question regarding automating some Outlook/IMAP and pdf parsing functions w/ ruby? — Ed Zimmerman <lists@...>

Hello,

20 messages 2013/03/07

[#405477] Compiling Ruby 2.0, problem with OpenSSL — "Piotr P." <lists@...>

Trying to compile Ruby 2.0 from source, having problem with it, getting

10 messages 2013/03/07

[#405495] RubyExcel class. Useful? — Joel Pearson <lists@...>

I've managed to create a (relatively) stable data-processing class which

32 messages 2013/03/08

[#405570] Confusion with block local variable declaration with block variable declaration within the pipe `|` — Love U Ruby <lists@...>

Why are we not allowed to create local variables or new object with

17 messages 2013/03/11

[#405597] Confusion with empty block printing — Love U Ruby <lists@...>

When I typed the below in my IRB:

18 messages 2013/03/11

[#405608] Access values for JSON.parse response — Nicole Villette <lists@...>

Hello, Does anyone know who to get the values from a nested hash in

17 messages 2013/03/11

[#405630] Confusion with some Module methods. — Love U Ruby <lists@...>

Can anyone help me to understand how the below module methods works?

16 messages 2013/03/12

[#405656] Confusion with Strings — Love U Ruby <lists@...>

From the book I read a line about string :

18 messages 2013/03/12

[#405762] Understanding Ruby Classes, Objects and Methods. — Kedar Mhaswade <lists@...>

Dear Rubyists,

12 messages 2013/03/13

[#405931] Finding one's way with 'super' in define_method/alias_emthod — Marcin Rzeźnicki <marcin.rzeznicki@...>

Hi all!

12 messages 2013/03/18
[#405935] Re: Finding one's way with 'super' in define_method/alias_emthod — Robert Klemme <shortcutter@...> 2013/03/18

On Mon, Mar 18, 2013 at 5:50 PM, Marcin Rze=C5=BAnicki

[#405936] Re: Finding one's way with 'super' in define_method/alias_emthod — "Marcin R." <lists@...> 2013/03/18

Robert Klemme wrote in post #1102151:

[#405942] Re: Finding one's way with 'super' in define_method/alias_emthod — Robert Klemme <shortcutter@...> 2013/03/18

On Mon, Mar 18, 2013 at 8:39 PM, Marcin R. <lists@ruby-forum.com> wrote:

[#405986] Ruby tainting on primitives — "Nicolas V." <lists@...>

Hi there,

18 messages 2013/03/20

[#405987] Why was the object_id for true and nil changed in ruby2.0? — Bharadwaj Srigiriraju <lists@...>

irb(main):001:0> true.object_id

11 messages 2013/03/20

[#406015] fixedpnt 0.0.1: Binary Fixed Point Calculations — Axel Friedrich <lists@...>

https://github.com/Axel2/fixedpnt.rb

12 messages 2013/03/20

[#406184] Nokogiri help parsing HTML — Paul Mena <lists@...>

I'm relatively new to Ruby (and therefore Nokogiri) and am trying to

18 messages 2013/03/26

[#406258] Translation Project — Jeremy Henderson <lists@...>

Hello all! This is my first post! I started learning Ruby about 3 weeks

22 messages 2013/03/28

[#406291] Hash with default — Harry Kakueki <list.push@...>

I would like to make a hash like h2 with the default described by h in one

12 messages 2013/03/29

[#406375] Ruby Gotchas presentation slides — Dave Aronson <rubytalk2dave@...>

I recently made available the slides for a presentation I did

13 messages 2013/03/30

[#406387] Private setters can be called by self, why not getters? — Josh Cheek <josh.cheek@...>

class Counter

9 messages 2013/03/31

Re: Translation Project

From: Julian Leviston <julian@...>
Date: 2013-03-29 01:57:42 UTC
List: ruby-talk #406284

On 29/03/2013, at 7:00 AM, Jeremy Henderson <lists@ruby-forum.com> =
wrote:

> Hello all! This is my first post! I started learning Ruby about 3 =
weeks
> ago and have a personal project I would like to do, so I was wondering
> if someone could help me out a bit, so I can get it started.
>=20
> I would like to have a request made by Ruby to the user for some text.
> Then Ruby would take their input and split the text up by every
> individual character and assign it a new value based on what letter it
> is.
>=20
> For instance if:
>=20
> "A" =3D [A,B,C,D,E,F] "B" =3D [G,H,I,J,K,L]
> "C" =3D [M,N,O,P,Q,R] "D" =3D [S,T,U,V,W,X,Y,Z]
>=20
> So with the info above, Ruby would look at a sentence like, "Hello
> World" and it would say, "Ok, "H" is in "B's" array, so it's new value
> is "B"... and would do that for each character in the text. Then, when
> it's done, it would show the result after it's been put together. So =
the
> final product would be, "BABBC DCCBA". Spaces being accounted for as
> they are shown in the original text.
>=20
> If you know how this would be done, I would greatly appreciate your
> help. Otherwise, if you know a portion of how it might work, I would
> appreciate that as well. I'm grateful for any help anyone could =
provide.
>=20
> Thank you
>=20
>=20

Hi Jeremy,

Ruby is a very concise and expressive programming language. It's =
possible to pack a lot of code in a short number of lines.

Thus, while this code that I wrote as a solution to your problem solves =
your problem, it's necessary to explain what it does.

input =3D "hello"
dict =3D {a: "abcdef", b: "ghijkl", c: "mnopqr", d: "stuvwxyz"}
puts input.each_char.map do |char|
  key, value =3D dict.detect{|key, value| value.include?(char)}
end.join


Here is an annotated version:

# set the input string to "hello"
input =3D "hello"

# create a Ruby Hash (also called a dictionary in some languages) and =
set it to the variable dict.
# we are using single letter strings for keys, and those keys are then =
defined by a string with a series of letters in each.=20
# Commas separate the key-value pairs, and keys are separated by values =
by =3D>
# thus, if we were to ask dict for what it defines as "a", we'd get back =
"abcdef"
# We can do this by saying dict["a"] and ruby will then return "abcdef"
# I suggest you read up on the Hash class and ruby hashes. They're very =
powerful and interesting.
dict =3D {"a" =3D> "abcdef", "b" =3D> "ghijkl", "c" =3D> "mnopqr", "d" =
=3D> "stuvwxyz"}

# this is an iterator - ie a loop. It's actually a reasonably complex =
one because I've chained two together.
# input.each_char will give an Enumerator, which effectively gives us =
the equivalent of an Array (a list) that has
# in it a series of strings, each with just one character in it. In =
other words, it will yield to us a series of items, each which
# is one single character string out of the "input" string.
# input.each_char.map is equivalent to setting a variable to =
input.each_char and then sending that variable
# the map message.
#=20
# now, map is a method that takes some enumerable object such as Array =
or Enumerator, and evaluates
# a chunk of code (called a block in ruby) on each element of that =
array. I.E. it gives us a new array where each element of the new
# array represents the result of evaluating the block of code that is =
passed to map against each element of the object that map is
# called on.
#=20
# it's much easier to understand it in examples than it is in =
explanation
# So, this is a good example:=20
# >> ["hello", "this", "is", "fun"].map{|item| item.upcase}
# this will yield:
# =3D> ["HELLO", "THIS", "IS", "FUN"]
# You can see each element of the input array, which is a string with a =
lowercase word in it, has been "processed" by the block (indicated with =
{} braces)
# in the block {|item| item.upcase}, item represents each element, and =
then the bit after (item.upcase) is the code that will be executed on =
each item.

# So, in summary, the following code goes through each character as a =
separate string and assigns it to the variable "char" in the block:
# the "puts" call just outputs the result of the input.each_char.map
puts input.each_char.map do |char|

# now, if we take the next bit in reverse, it'll be more easy to =
explain. There are three parts to it:
#
# string objects (in fact most enumerables) have a method called =
"include?" which basically returns true if it is included
# So:
# >> "doggie".include?("dog")
# =3D> true
# should make sense
#
# Hash or dictionary objects have a method called detect (or find) which =
is an iterator/enumerator that looks over each
# key and value pair, and returns the first pair (as an array) where the =
block it takes evaluates to true
# thus:
# >> {"hello" =3D> "goodbye", "yes" =3D> "no"}.detect{|key,value| key =3D=3D=
 "yes"}
# =3D> ["yes", "no"]
# ... should come as no surprise
#=20
# now, ruby has a way of pulling out values of an array and assigning =
them to other variables
# it's called multiple assignment and this should explain it
# >> x,y =3D [3,4]
# =3D> [3, 4]
# >> x
# =3D> 3
# >> y
# =3D> 4
# so, x is 3 and y is 4.
#
# so what I'm doing in the next line of code is assigning key and value =
to be the key and value of the first element
# of the dict variable whose value includes the char variable's value.
  key, value =3D dict.detect{|key, value| value.include?(char)}

# that is then returned as the result of the map. At this point, we =
would be fine to simply put end to mark the end of the map block
# (ruby can use {} or do ... end to mark blocks)
# but we want to build the single-char strings array into a single =
string. We do that with join.
# ie:
# >> ["cool", " beans"].join
# =3D> "cool beans"

end.join

# and that's all! :)
# hope that helped!

Julian


In This Thread