Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- There's a method that lets you substitute a bunch of characters for a corresponding set of characters
- (it's not gsub). Find that method and use it in a code sample.
- # Element assignment ([]=) is a method:
- irb> str = "rlabuonora@yahoo.com"
- => "rlabuonora@yahoo.com"
- irb> str.methods
- => [:<=>, :==, :===, :eql?, :hash, :casecmp, :+, :*, :%, :[], :[]=,
- ...
- # str[] is syntactic sugar for str.[]=
- irb> str.[]=(0, "s")
- => "s"
- irb> str
- => "slabuonora@yahoo.com"
- # you can user integers in []
- irb> str[0] = "r"
- => "r"
- irb> str
- => "rlabuonora@yahoo.com"
- irb>
- # but also ranges
- irb> str[(0..10)] = "*" * 10
- => "**********"
- irb> str
- => "**********yahoo.com"
- # and even regular expressions
- irb> str = "rlabuonora@yahoo.com"
- => "rlabuonora@yahoo.com"
- irb> str[/@(.*).com/] = "@gmail.com"
- => "@gmail.com"
- irb> str
- => "rlabuonora@gmail.com"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement