Created
May 29, 2015 06:50
-
-
Save bradbergeron-us/691a01be8d51bf949972 to your computer and use it in GitHub Desktop.
backtick overriding
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # backtick is a kernel operation in Ruby | |
| # which mean it can be overridden | |
| # backtick method is called on the implicit receiver (that is, “self”). That means that you # can do this: | |
| ''' | |
| #! bin/env ruby | |
| require 'net/http' | |
| class Google | |
| include BacktickURI | |
| def search_page_html | |
| url = `http://www.google.com/` | |
| res = Net::HTTP.start(url.host, url.port) {|http| | |
| http.get('/') | |
| } | |
| res.body | |
| end | |
| end | |
| ''' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment