Elastic objects in ruby

Here is an example of an elastic object wrapper in ruby

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
class ElasticObject

attr_reader :object
alias_method :value, :object
def initialize(object)
@object = object
end

def method_missing(method, *args, &block)
return ElasticObject.new(object.send(method, *args, &block)) if object.respond_to?(method)

return ElasticObject.new(nil) if !object.is_a?(Hash)

result = [method] if key?(method)
result = [method.to_s] if key?(method.to_s)
return ElasticObject.new(result)
end

end

emp = ElasticObject.new({"name" => "Mujju", "age" => 1})


puts emp.dob.month # => nil
puts emp.name # => "Mujju"


I am currently working on LiveForm which makes setting up contact forms on your website a breeze.