Last active
August 29, 2015 14:24
-
-
Save kalyco/cb7ad6483fcbc5e27166 to your computer and use it in GitHub Desktop.
short example of send() method in rails
This file contains 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
class Car | |
def start | |
puts "vroom" | |
end | |
private | |
def engine_temp | |
puts "Just Right" | |
end | |
end | |
@car = Car.new | |
@car.start # output: vroom | |
@car.send(:start) # output: vroom | |
#biggest difference is send lets you posted to private methods: | |
@car.engine_temp # This doesn't work, it will raise an exception | |
@car.send(:engine_temp) # output: Just Right |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment