Mohammed said:
Can I use ruby code running in web browser without any frameworks used?
The key thing to think about is, how does an incoming HTTP request end
up being processed by your ruby code? There are several options.
(1) Probably the most common option is to run a webserver written *in*
ruby (e.g. webrick), or in a combination of ruby and C (e.g. mongrel,
thin, unicorn). They will make a call to your code when the request
comes in.
Your app runs as a separate process, and listens on its own TCP socket.
So your URL might be something like
http://x.x.x.x:4567/
If desired, you can proxy to this from another webserver in front.
(2) You can run Apache or Nginx with Phusion Passenger, a.k.a.
mod_rails. This integrates into the webserver, starting ruby processes
as necessary and passing HTTP requests to them using the Rack API.
(3) Your webserver can run your ruby script as a CGI, which means it
starts a new process running your script for each incoming request,
passing the request on STDIN and the headers in environment variables,
and getting the response on STDOUT. This is inefficient because it
involves starting a whole new ruby interpreter for each request. It
becomes extremely inefficient if your ruby code in turn loads lots of
other ruby libraries.
(4) There are some other options like FastCGI and SCGI, rarely used now.
Fortunately, all these options support mapping HTTP requests to the same
API: Rack. If you write your code using Rack, or any other framework
which sits on top of Rack (including Rails, Sinatra, Camping), then you
can run the same code under any of the above scenarios, just by changing
a config file.
Also anyone please tell me how to make framework, Please give me some
tips
or spark to start with.
I need to make a new framework because I need to re-use the ruby code
(actually shares the code) for desktop version and the new framework.
That depends on what you mean by "framework". Normally "framework" means
code someone has already written, that you plug your customisations
into. You don't write a new framework from scratch, you just pick one
and extend it.
For code which is shared between a desktop app and a web app: just put
it in a library (lib/foo.rb) which can be used by either.
To be honest, if you write a good web app, you won't need a desktop one,
and it will save you a lot of pain installing graphic libraries and
frameworks. Everyone has a browser; just point it at localhost. This is
where the web server written *in* ruby comes into its own.