Professional Documents
Culture Documents
"SOAPEnvelope="
"Snapshot= ",
Tk applications follow a widget hierarchy where
any number of widgets may be placed within
"ResponseParam= "
another widget, and those widgets
within another
LAST);
widget, ad infinitum. The main widget in a Tk
StepName Text describing the Web Services step
program is referred to as the root widget and can be
(Any free text).
created by making a new instance of the TkRoot
URL -URL of the Web service
class.
SOAP Envelope This field has the XML string that is
accepted by the web service. The AD team should
following result -
Create the widgets, place them in the interface, and
finally, bind the events associated with each widget
to a method. 1.10: Ruby/Tk WidgetClasses
There are three geometry managers; place,
Q.39 Explain Ruby/Tk widget classes ?
grid and pack that are responsible for controlling the
Ans.: There is a list of various Ruby/Tk dasses, which
size and location of each of the widgets in the
can be used to create a desired GUl using Ruby/Tk.
interface.
TkFrame creates and manipulates frame widgets.
Q.37 Define the Installation of RubyTk?
TkButton creates and manipulates button widgets
Ans.: The Ruby Tk bindings are distributed with Ruby
but Tk is a separate installation. Windows users can .TkLabel creates and manipulates label widgets.
download a single cick Tk installation from Active .TkEntry creates and manipulates entry widgets.
check
State's ActiveTcl.
TkCheckButton creates and manipulates
Mac and Linux users may not need to install it because button widgets
there is a great chance that its already installed along and manipulates radio
TkRadioButton creates
with OS but if not, you can download prebuilt button widgets.
packages or get the source from the Tel Developer.TkListbox creates and manipulates list box widgets
Xchange. and list box
TkComboBox creates manipulates
1.4: Ruby and Web
I you call this script test.cgi and uploaded it to a Unix-based Web hosting provider with the right
permissions, you could use it as a CGI script.
FOr if you have the Web site https://www.example.com/hosted with a Linux Web hosting
example,
provider and you upload test.cgi to the main directory and give it execute permissi a5, then
VISiting https://www.example.com/test.cgi.should return an HTML page saying This is a test.
Here when test.cgi is requested from a Web browser, the Web server looks for test.cgi on the Web site, and
then executes it using the Ruby interpreter. The Ruby script returns a basic HTTP header and then
retums a basic HTML document.
Using cgi.rb
Ruby comes with a speial library called cgi that enables more sophisticated interactions than those with
the preceding CGI script.
Let's create a basic CGI script that uses cgi-
#l/usr/bin/ruby
require cgi'
cgi = CG" new
puts cgi.header
puts<html><body> This is a test </body> </html>"
Here, you created a CGI object and used it to print the header line for you.
class return while Q.6 Explain Rails ?
recruiters, consulting firms, conferences, businesses The advantage of establishing conventions might
that build websites with Rails, and investors that seem obvious, but when Rails released in 2004,
was
fund startups. Rails is popular among web startups, web development was dominated by PHP, which
signiticantly because the pool of opern source lent itself to idiosyncratic code produced by solo
software libraries (RubyGems, or "gems") makes it webmasters, and Java frameworks such as Struts,
possible to build complex sites quickly which were often seen as burdened by an excess of
Read on for a more detailed look at Rails. First, we'll structure.Other frameworks, such as Apple's
look at why Rails uses the Ruby programming WebObjects, Adobe's ColdFusion, and Microsoft's
language. We'll consider why Rails is popular, NET Framework, were in wide use but the
review some basic concepts, then look at Rails from frameworks were products controlled by the
six different perspectives to understand it better. companies and built by small teams, which tended
2.1:Extending Ruby VALUE CTest;
* void Init _my_test(1
Q.1 Define extending ruby. CTest= rb_define_class("MyTest, rb_cObject):
Ans.: It is easy to extend
Ruby with new
features by rb_define_method(cTest, "initialize', t_init, 0):
writing code in
Ruby. Once you start Tb_define_method(cTest, "add"t_add, 1):
low-level code written in C, adding in id push = rb_intenml'push");
however, the
possibilities are endless.Extending Ruby with C is
pretty easy. For instance, suppose we are
a custom
building 2.2.1:Bullding Our Extension
Internet-ready jukebox for the Sunset
Diner and Grill. Q.2 What is building our extenslon ?
.The extension we write will have Ans.: We'll have a lot more to
the same say about building
functionality as the following extensions later. For now,
though, all we have to do is
Ruby class. follow these steps.
class MyTest def initialize@arr Array.new end = Create a file called extconf.rb in the
def add(obj) @arr.push{obj) end as our my_test.c C source file
same
directory
end
file. The file extconf.rb should contain the
That is, we'll be
writing an extension in C that is following two lines.
plug-compatible with that Ruby class.
require 'mkmf
The
equivalent code in C should look somewhat
Create makefile("my_test")
familiar.
Run extconf.rb. This will
#inchude 'ruby h" generate a Makefile.
static int id
push; % ruby extconf.rb
static VALUE _init(vVALUE self)
Creating Makefile
Use make to build the extension. This is what
VALUE ai
arr = rb_ary_new(); happens on an OS X system.
rb_iv_set(self, "@arr, arr); % make
return self;
gcc-fno-common-8-02-pipe -fno-common-I.
static VALUE _add(VALUE self, VALUE obj) .-lusr/lib/ruby/1.9/powerpc-darwin7.4.0
VALUE arr
.-I/usr/lib/ruby/1.9/powerpc-darwin74.0 «
arr = rb_iv_get(self, "@arr);:
my_test.c
Tb_funcall(ar, id _push, 1, obj);
cc
dynamic -bundle -undefined suppress
return arr; -flat_namespace
lusT/ib -o my_test bundle my_test o-ldl lobjc A class is u*d to speity the torm ot an oOet ant
The result of all this the extension, all
n
ncely t combines data rupreentatuon and methede tr
bundled up in a shared object manipulating that data nto one neat packag The
(a so
dll, or fon 0S X]a bundle) data and ethods within
class ar talini
members of the class
2.1.2 Rules for Running Our Extension
2.2.1: Working of Immediate Objects
Q.3 What b rules for running our extenslon ?
Ans. We can use our extension from a.5 Define Working of Immediate Objecte
Ruby simply
by require-ing it dynamically at runtime (on most Ans. : As we said above, immediate vaiues
a o
platforms) We can wrap this up in a test to verity pointers Fixnum, Symbol, true. tale, and nil are
that
things are working as we expect. stored directly in VALUE
require my_test Fixnum values are stored as 31-bit numbersl that
require test/unie' are formed by shift1ng the onginal number lett
class TestTest< Test:Unit: TestCase bit and then setting the 1SB. or least significant bt
def test_test (bit 0). to l When VALUE is used as a pointer te
specific Ruby structure, it is guaranterd always to
t-MyTest.new have LSB of
an zero. the other immediate values
assert_equal(©bject, MyTest.superclass) also have LSB» of zero Thus,
assert equal(My
Test, t.class) a
s1mple bit test can
tell you whether you have a Fixnum This test is
tadd(1) Wrapped in a macro, FIXNUM_P
tadd(2) Similar tests let you check tor ther
assert_equal([1.2], tinstance_eval("@arr")) values.
immediat
end
FIXNUM_P(value) nonzero it value is
a
end
Fixnum
produces: .SYMBOL_P(value)
Finished in 0.000479 seconds.
nonzero if value 1
Symbol
1 tests, 3 assertions, 0 failures, 0 errors NIL P(value) - nonzero if value is nil
Once we're happy that extension works, RTEST(value)- nonzero if
our we value neithet
can then install it globally by nor false
is
ni
running make install.
T h e other immediate aluo
Cusr/lib -o
my_test.bundle my_testo -ldl-lobjc A class is used to specity the torm of an obut and
The result of all this the extension, all it combines data repre*ntation and methoxds for
is
nicely
bundled up in a shared object (a .so, manipulating that data into one neat package The
dll, or lon OS XJ data and methods within class calied
a bundle) a
ar
members of the class
3. Create extconf.rb
ruby nun
call Here's an
example
inchude 'ruby h
K u n extcont.rb to
create a Makefile for the C files
this directory
in an(vola)
O u r own applicatiorn stuff. "/
5. Run make.
ruby_init(
6. Run make
install. ruby_init_loadpath().
ruby_scriptl'embedded').
2.42:To Create tD_Joad_ hle('start rb')
A File
ruby_nun().
a.11 Define to create a file. exit{0): }
Ans.: C
data type wrapplng 1o initialize the
Ruby interpreter, you need
VALUE to call
mark). Data_WrapStructlVALUE
vod ("freeXO. "ptr)void
class. void
ruby_inat)
to take
But on some
plattorms, you may need
special steps before that.
Wraps the given C datary pe ptr, registers the "if defined(NT) Ntinitialize(&argc,
two &argv)
garbage collection routines (ee below), and retums endif
a #if
TErMA detined(MACOS&a defned MWERKS
argc ccommand(&argv).
endif Let's write a C program that calls an instance of ths
aenned
HNCA
argc= ccommand(&argv).
Lets rile C
"endif a
program that calls an instance of this
ee main.c class multipe times. To create the instance.
in the Ruby distribution tor any other
welget
special detines the class object (by looking tor
or
setup nevded for yonur
platform
a
top-level comstant
Tou whose n.anme is the
ne the Ruby name of our class) Wel then a<k
actessiDIe
inchude and ibrary hles
Ruby to create an instance
to
cumpile this embedded oxde On my o tha
box (Mac 0S X) I have the
Ruby 18
mterpreter
lass-rb_class_new_instanoe
lass.new. he two
s
actualy a call to
installed in a nutial
parameters are the
private directory, so my Makefile
looks like this argument count and dummy pointer to the
arguments themselves.)
WHERE-/Usersidave/nuby1 Nib/ruby/1 8/powerp O n c e we have that
object, we can invoke t s sum
darwin/ CFLACS-S(WHERE) method ustng rb_funcall
LDFLAGSLS(WHERE) -Iruby -dl -lobjc embet #include ruby.h
embed
oS(CC)-o embd embedo S(LDFLAGS) static int id_sum
The second of int Vahues||l =(5. 10, 15, -1. 20. 0)
way embedding Ruby alkws
Ruby
code and your C code static VALUE Wrap_sum(VALUE args)
to
engage in more of a
rubyfinalize()
exit(0)
API Embedded Ruby APl void ruby_init() Sets C
also eruby.
within another program, see
interpreter
we've
.Bridging Ruby Languages So far,
to Other
routines
discussed extending Ruby by adding
written in C.
can just about
write extensions in
Howeve, you
can bridge the
two
as long as you
any language,
Almost anything is possible,
languages with C.
and C+,
awkward marriages of Ruby
including
But you may be able to
Ruby and Java, and so on.
languages using
COM.