# FSDB to turn file systems into applications

**URL:** <https://www.ruby-forum.com/t/fsdb-to-turn-file-systems-into-applications/81661>\
**Category:** Ruby\
**Created:** [March 14, 2006, 10:48am UTC](https://www.ruby-forum.com/t/fsdb-to-turn-file-systems-into-applications/81661 "2006-03-14T10:48:55Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![unknown](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/4bbf92/32.png) [@unknown](https://www.ruby-forum.com/u/unknown)\
**Post date:** [March 14, 2006, 10:48am UTC](https://www.ruby-forum.com/t/fsdb-to-turn-file-systems-into-applications/81661/1 "2006-03-14T10:48:55Z")

</div>

In search for a simple database system that’s also an an universal  
application service ( similar to Frontier) I’ve started again to play  
around with FSDB. By accident I’ve found out that this way every file  
system can be turned into an application. Using the incredible powerful  
“method\_missing” construct the following code was implemented:

require ‘fsdb’

@@root = FSDB::Database.new(’/tmp/examples’)  
@@path = ‘’

script = \<\<MY\_SCRIPT  
def show\_it(a,b)  
puts a.to\_s + b.to\_s  
end  
MY\_SCRIPT

script2 = \<\<MY\_SCRIPT  
def make\_it(a,b)  
puts a + ’ : ’ + b  
end  
MY\_SCRIPT

script3 = \<\<MY\_SCRIPT  
def hello\_method  
write\_it(“Hello World!”)  
end  
def write\_it(txt)  
puts txt  
end  
MY\_SCRIPT

@@root[’/scripts/myscripts/show\_it’] = script  
@@root[’/scripts/make\_it’] = script2  
@@root[’/scripts/hello\_method’] = script3  
@@root[’/values/a’] = 25  
@@root[’/values/b’] = 35  
@@root[’/values/array’] = [31,2,3,4]

class \<\<  
def method\_missing(method\_name,\*args )  
@@path \<\< ‘/’ + method\_name.to\_s  
if !(File.directory?(@@root.absolute("#{@@path}")))  
res = @@root["/#{@@path}"]  
if res.to\_s.include? “def”  
if !(methods.include? method\_name)  
eval res  
@@path = ‘’  
return send(method\_name,\*args)  
end  
end  
@@path = ‘’  
return res  
end  
end  
end

scripts.myscripts.show\_it(“one”,“two”)  
scripts.make\_it(“one”,“two”)  
scripts.hello\_method()

puts values.a + values.b

myVal = values.array + [5,6,7,8]  
puts myVal.to\_s

So my question is: has someone else used “method\_missing” this way and  
are there any “show stoppers” to use “method missing” this way. I’m  
planning to use this idea for a very important project and I want to  
try to avoid to run into troubles because of a lack of experience.

- Tom

---

<div class="post-metadata">

**Author:** ![unknown](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/4bbf92/32.png) [@unknown](https://www.ruby-forum.com/u/unknown)\
**Post date:** [March 14, 2006, 9:09pm UTC](https://www.ruby-forum.com/t/fsdb-to-turn-file-systems-into-applications/81661/2 "2006-03-14T21:09:39Z")

</div>

> So my question is: has someone else used “method\_missing” this way and  
> are there any “show stoppers” to use “method missing” this way. I’m  
> planning to use this idea for a very important project and I want to  
> try to avoid to run into troubles because of a lack of experience.

Generally method\_missing magic may lead to infinite recursion loops,  
which are quite annoying. I would suggest to allow this kind of magic  
only in special blocks, which are evaled in the instance scope of a  
database object.

class Database  
def initialize(root)  
@root = FSDB::Database.new(root)  
end  
def method\_missing  
…  
end  
def with(&block)  
instance\_eval(&block)  
end  
end

db = Database.new("/tmp/examples")

db.with do  
scripts.myscripts.show\_it(“one”,“two”)  
scripts.make\_it(“one”,“two”)  
scripts.hello\_method()  
end

Note, that you lose the instance scope, so methods and instance  
variables are not available in the block.

How about recognizing accessor calls for writing to the database?
