ruby-uebungen/Assignment_035/solution/readme.md

21 lines
568 B
Markdown

# Lösung: Reguläre Ausdrücke: Matching
<div style="border: 1px solid grey;"><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br></div>```ruby
def reverser(s)
/(.*) (.*)/ =~ s
"#{$2} #{$1}"
end
puts reverser("Ruby Programmierer")
```
Alternative Lösung:
```ruby
def reverser(s)
m = /(.*) (.*)/.match(s)
"#{m[2]} #{m[1]}"
end
puts reverser("Ruby Programmierer")
```