Ruby we might Miss

This is the continuation part of the series I started.
The topic for this post :


String#%(args) interpolates the arguments into itself in the manner of sprintf. To provide
more than one value for interpolation, you must supply an array.
“%.5f” % Math::PI # => “3.14159”
“%.5f, %.5f” % [Math::PI, Math::E] # => “3.14159, 2.71828”

• String#[](regex) returns the portion of the string that matches the given regular
expression. If there is no matching portion, nil is returned.
“asdf”[/sd/] # => “sd”
“asdf”[/^sd/] # => nil
“asdf”[/d(.)/,1] # => “f”

• String#scan(regex) collects all of the regular expression’s matches against the string
into an array. If the pattern has captures, each element of the array is itself an array of
captured text.
“asdf”.scan(/[a-e]/) # => [“a”, “d”]
“hello ruby; hello regex”.scan(/hello (\w+)/) # => [[“ruby”], [“regex”]]

2 responses to “Ruby we might Miss

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s