ruby-uebungen/Assignment_031/solution
Thomas Smits 58bc23516c Update of exercises 2023-05-25 17:49:42 +02:00
..
readme.md Update of exercises 2023-05-25 17:49:42 +02:00

readme.md

Lösung: Reguläre Ausdrücke: Matching

def reverser(s)
  /(.*) (.*)/ =~ s
  "#{$2} #{$1}"
end

puts reverser("Ruby Programmierer")

Alternative Lösung:

def reverser(s)
  m = /(.*) (.*)/.match(s)
  "#{m[2]} #{m[1]}"
end

puts reverser("Ruby Programmierer")