Skip to content

Instantly share code, notes, and snippets.

View balramkhichar's full-sized avatar
:octocat:
May the --force be with you

Balram Khichar balramkhichar

:octocat:
May the --force be with you
View GitHub Profile
@balramkhichar
balramkhichar / react-native-watchman-clear.txt
Last active February 1, 2018 09:44
React native and watch cache clean
watchman watch-del-all && rm -rf $TMPDIR/react-* && rm -rf node_modules/ && npm cache clean && npm install && npm start -- --reset-cache
def location_in_hierarchy(object, method)
history = []
current = object.class
history << current
while (current.superclass!=nil)
history << current.superclass
current = current.superclass
end
history = history.reverse
history.find do |ob|
@balramkhichar
balramkhichar / method_missing
Created December 15, 2014 18:14
method_missing blog post
What is method_missing ?
When we send a message to an object, it first method it finds on its method lookup path with the same name as message. If it fails to find any method like this then it will raise NoMethodError exception.
method_missing is a known tool in the Ruby meta-programming toolbox. It’s a callback method that gets called when an object tries to call a method that is missing. An example of this is dynamic finders in ActiveRecord. Let's say Member has an email attribute, you can do Member.find_by_email('balram@codebrahma.com') and the interesting fact is that User and ActiveRecord::Base have not defined it.
example:
class MyClass