P
Power One
Hello once again folks!
OK, I'm still extremely new to Ruby, so if my question is stupid, please
be gentle .
The code below is an example from a ruby book, and I look at it, I
understand most of it, but what I don't understand is why the
author/ruby-expert has \b in the regular expression (I know it's a
backspace), but why match for a backspace especially it's outside of the
bracket, and why the brackets? In this context, I'm confused! I'm
talking about line number 3! Any clarification or insight would be
really helpful to me. Thank you!
class WordPlay
def self.switch_pronouns(text)
text.gsub(/\b(I am|You are|I|You|Me|Your|My)\b/i) do |pronoun|
case pronoun.downcase
when "i"
"you"
when "you"
"me"
when "me"
"you"
when "i am"
"you are"
when "you are"
"i am"
when "your"
"my"
when "my"
"your"
end
end.sub(/^me\b/i, 'i')
end
OK, I'm still extremely new to Ruby, so if my question is stupid, please
be gentle .
The code below is an example from a ruby book, and I look at it, I
understand most of it, but what I don't understand is why the
author/ruby-expert has \b in the regular expression (I know it's a
backspace), but why match for a backspace especially it's outside of the
bracket, and why the brackets? In this context, I'm confused! I'm
talking about line number 3! Any clarification or insight would be
really helpful to me. Thank you!
class WordPlay
def self.switch_pronouns(text)
text.gsub(/\b(I am|You are|I|You|Me|Your|My)\b/i) do |pronoun|
case pronoun.downcase
when "i"
"you"
when "you"
"me"
when "me"
"you"
when "i am"
"you are"
when "you are"
"i am"
when "your"
"my"
when "my"
"your"
end
end.sub(/^me\b/i, 'i')
end