--- layout: post title: "Every day learing" date: 2016-01-14 categories: learning --- Ghost Methods

From the caller’s side, a message that’s processed by method_missing looks like a regular call—but on the receiver’s side, it has no corresponding method. This trick is called a Ghost Method.

Dynamic Proxies

When an object(wrapper object that contain other object) receive ghost method call and simply use that call to get data from contained object is called Dynamic Proxies.

Every time we override method_missing(for use ghost method) we should also override respond_to_missing? Because ghost method call on respond_to? will not respond.

module const_missing method

When you reference a constant that doesn’t exist, Ruby passes the name of the constant to const_missing as a symbol. Class names are just constants

N.B: When we use ghost method need to extra carefull because it may cause infinity call

Ruby class is not special thing it just give us new scope

Solve Rubymine keyboard freez problem Keyboard input may be unlocked by restarting IBus daemon from a console: ibus-daemon -rd IBus can be disabled for IDEA by unsetting env. variable XMODIFIERS, but ability to input national characters in IDEA will be lost: XMODIFIERS="" idea.sh I have used the second one and fixed my problem.

@indicate inctace objecct of self. If during declaretoin of @var self is class then it class es instace objeect, if self indicate obje then it object's instance variable.

Like other programming language, ruby instance variable is not open to out side world(class).{In java public inctance variable is accessabe using dot(.) operator outside of class}So, to access variable we have to declare getter/setter method in ruby.(There are many way to access variable in ruby like instace_variable_get, instacnce_eval, eval

We can make flat scope for sharing local variable between two or more methods

Example of flat scope my_var = "Success" MyClass = Class.new do "#{my_var} in the class definition" # Have to use dynamic method creation to access my_var define_method :my_method do "#{my_var} in the method" end end puts MyClass.new.my_method # => Success in the method

Difference between undef_method and remove_method in ruby

You can remove a method in two easy ways. The drastic Module#undef_method( ) removes all methods, including the inherited ones. The kinder Module#remove_method( ) removes the method from the receiver, but it leaves inherited methods alone. See below 2 simple example - Example 1 using undef_method class A def x puts "x from A class" end end class B < A def x puts "x from B Class" end undef_method :x end obj = B.new obj.x result - main.rb:15:in ': undefined methodx' for # (NoMethodError) Example 2 using remove_method class A def x puts "x from A class" end end class B < A def x puts "x from B Class" end remove_method :x end obj = B.new obj.x Result - $ruby main.rb x from A class

Issues using div with in `a` tag

Normally div with in a tag is not allowed. If we need apply display: display on a tag. Again we are not able to use a tag with in a tag.