--- 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 ProxiesWhen 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 methodWhen 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
var = 1, obj.instance_exec(var) {|var| var }
where we pass var local's to boj scope
Class.new(var)/Module.new(var)
passing var to class & module scope.
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
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.