Ruby/C3/Object-Oriented-Concept-in-Ruby/Gujarati

From Script | Spoken-Tutorial
Revision as of 10:11, 29 October 2014 by Jyotisolanki (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search


Time Narration
00:01 Ruby માં Object Oriented Concept પરનાં સ્પોકન ટ્યુટોરીયલમાં તમારુ સ્વાગત છે.
00:06 આ ટ્યુટોરીયલમાં આપણે આપેલનો ઉપયોગ કરતા શીખીશું
00:08 classes
00:09 objects બનાવવું
00:10 Ruby માં methods (મેથડો) વ્યાખ્યિત કરવાના વિવિધ માર્ગો.
00:13 અહી આપણે વાપરી રહ્યા છીએ.
00:14 Ubuntu આવૃત્તિ 12.04
00:16 Ruby 1.9.3
00:19 આ ટ્યુટોરીયલનાં અનુસરણ માટે, તમને Linux નાં આદેશો, Terminal (ટર્મિનલ) અને Text-editor (ટેક્સ્ટ-એડિટર) નું જ્ઞાન હોવું જરૂરી છે.
00:24 જો નથી, તો સંબંધિત ટ્યુટોરીયલો માટે, અમારી વેબસાઇટની મુલાકાત લો.
00:28 શરૂઆત કરવા પહેલા, યાદ કરો કે આપણે “ttt” નામની એક ડીરેક્ટરી પહેલા બનાવી હતી.
00:33 ચાલો એ ડીરેક્ટરી પર જઈએ.
00:35 ruby hyphen tutorial અને classes ડીરેક્ટરી પર જઈએ.
00:41 Ruby એક object oriented ભાષા છે.
00:44 વેલ્યુંથી લઈને string અથવા ક્રમાંક Ruby માં આ બધુજ કઈ ઓબજેક્ટ છે.


00:49 class (ક્લાસ) એ સંદર્ભિત data (ડેટા) અને functions (ફંક્શનો) નો સંગ્રહ છે.
00:53 તેને માહિતી વ્યવસ્થિત રાખવા માટે રાખી શકાવાય છે.
00:56 objectclass નું ઇનસ્ટેનશીએશન છે.
01:00 class ની વ્યાખ્યા class કીવર્ડથી શરુ થાય છે.
01:05 તેની આગળ class નું નામ આવે છે.
01:08 તેને “end” દ્વારા સીમાંકિત કરાય છે.


01:11 ચાલો class નાં ઉદાહરણ જોઈએ.
01:14 class Product (ક્લાસ પ્રોડક્ટ)
01:16 ruby code (રૂબી કોડ)
01:17 end (એન્ડ)
01:20 ક્લાસનું નામ કેપિટલ અક્ષરથી શરુ થવું જોઈએ.
01:24 એકથી વધારે શબ્દ ધરાવતા નામ camelcased હોવા જોઈએ.
01:28 ઉદાહરણ તરીકે,
01:30 UserInformation (યુઝરઇન્ફોર્મેશન)
01:32 ProductInformation (પ્રોડક્ટઇન્ફોર્મેશન)
01:34 અનુગામી ફાઈલ નામોમાં શબ્દો જુદા કરવા માટે અન્ડરસ્કૉર રહેશે:


01:37 user underscore information
01:40 product underscore information
01:45 સામાન્ય સ્તરનાં Ruby ટ્યુટોરીયલોમાં બતાવ્યા પ્રમાણે gedit માં એક નવી ફાઈલ બનાવો.
01:48 તેને class_definition.rb નામ આપો.
01:52 મારી પાસે ક્લાસનાં અમલીકરણનાં કાર્યરત ઉદાહરણ છે.
01:57 તમે ટ્યુટોરીયલ અટકાવીને, આગળ વધીએ તેમ કોડ ટાઈપ કરી શકો છો.
02:02 આ ઉદાહરણમાં મેં Order નામનું ક્લાસ વ્યાખ્યિત કર્યું છે.
02:05 હવે ક્લાસને ઉપયોગી બનાવવા માટે ચાલો અમુક વેરીએબલો ઉમરીએ.
02:11 ત્યારબાદ મેં “myinstance” આ ઇન્સટન્સ વેરીએબલ વ્યાખ્યિત કર્યું છે.
02:15 અને મેં તેને એક વેલ્યુ આપી છે.
02:18 સાથે જ મેં “myclassvar” નામનો ક્લાસ વેરીએબલ પણ વ્યાખ્યિત કર્યો છે.
02:21 અને મેં તેને એક વેલ્યુ આપી છે.
02:24 ચાલો હવે આ ક્લાસને ઉપયોગી બનાવવા માટે અમુક કોડ ઉમેરીએ.
02:30 ટાઈપ કરો puts Order dot instance underscore variables.


02:36 આ લાઈન પહેલા, નવી લાઈન માટે ઉમેરો puts અમુક અક્ષરો slash n.
02:43 ચાલો તેને કોપી કરી તેને ઉમેરાયેલી આ લાઈન નીચે પેસ્ટ કરી સેવ કરીએ.
02:51 ચાલો હવે આ કોડ એક્ઝીક્યુટ કરીએ.
02:53 ટર્મિનલ પર જાવ અને ટાઈપ કરો.
02:56 ruby space class underscore definition dot rb
03:02 અને આઉટપુટ જુઓ.
03:05 તમને પોતે વ્યાખ્યિત કરેલું ઇન્સટન્સ વેરીએબલ દેખાશે.
03:09 હવે ચાલો ટાઈપ કરીએ puts Order dot class underscore variables
03:15 ડીમાર્કેશનને કોપી કરી, લાઈનની નીચે પેસ્ટ કરો અને તેને સેવ કરો.
03:21 હવે ચાલો ટર્મિનલ પર જઈએ અને પહેલાની જેમ ફાઈલ એક્ઝીક્યુટ કરીએ.
03:26 તમે જોશો કે ક્લાસ વેરીએબલ જે તમે વ્યાખ્યિત કર્યો હતો, તે પણ દેખાય છે.
03:32 હવે તમે પોતાનો ક્લાસ લખવામાં સમર્થ છો.
03:35 આગળ, ચાલો જોઈએ કે ઓબજેક્ટ શું છે.
03:40 ઓબજેક્ટ એ ક્લાસનું એક ઇન્સટન્સ છે.
03:43 જેનો એ અર્થ થાય છે કે ઓબજેક્ટ ક્લાસમાંથી બનેલ છે.
03:46 ક્લાસમાં વ્યાખ્યિત કરેલ પ્રોપર્ટીઓ અને મેથડો ઓબજેક્ટમાં હોય છે.
03:52 એક ઓબજેક્ટ તમે કેવી રીતે ડીકલેર કરો છો.
03:54 new keyword વાપરીને આપણે ક્લાસનો ઓબજેક્ટ ડીકલેર કરીએ છીએ.


03:58 અહીં આપણે Product class નો ઓબજેક્ટ ડીકલેર કરી રહ્યા છીએ.
04:02 અહીં એક ઓબજેક્ટ બને છે.
04:05 product = Product.new
04:09 આ પ્રક્રિયાને ઓબજેક્ટનું initialization (ઇનીશલાઈઝેશન) કહેવાય છે.
04:12 આ ઓબજેક્ટ એ type: Product છે.


04:16 હવે ચાલો જોઈએ કે initialize (ઇનીશલાઈઝ) મેથડ શું છે.
04:20 ઓબજેક્ટ બનતી વખતે initialize method બોલાવવામાં આવે છે.


04:26 On calling new on an object, we invoke the initialize method.

object પર new બોલાવતી વખતે, આપણે initialize method આવ્હાન કરીએ છીએ.

04:31 An initialize method may take a list of parameters.

initialize મેથડ parameters ની યાદી લઇ શકે છે.

04:37 Like other Ruby methods, it is preceded by the “def” keyword.

અન્ય Ruby મેથડની જેમ જ, તેની આગળ “def” કીવર્ડ મુકાય છે.

04:43 Let us look at an example.

ચાલો ઉદાહરણ તરફે જોઈએ.

04:46 Create a new file in gedit as shown in the basic level Ruby tutorials.

સામાન્ય સ્તરનાં Ruby ટ્યુટોરીયલમાં દર્શાવ્યા પ્રમાણે gedit માં એક નવી ફાઈલ બનાવો.

04:50 And name it object undescore initialize dot rb

અને તેને object undescore initialize dot rb નામ આપો.

04:55 I have a working example of the object initialization code.

મારી પાસે object initialization કોડનું કાર્યરત ઉદાહરણ છે.

05:00 You can pause the tutorial, and type the code as we go through it.

તમે ટ્યુટોરીયલ અટકાવીને, આગળ વધીએ એમ કોડ ટાઈપ કરી શકો છો.

05:04 Here I have defined a class called “Order”

અહીં મેં “Order” નામનો એક ક્લાસ વ્યાખ્યિત કર્યો છે.

05:08 Then I have defined the initialize method, with no argument.

ત્યારબાદ મેં argument વગર, initialize method વ્યાખ્યિત કર્યું છે.

05:13 I have defined a puts method to display the message “I have created an object”.

“I have created an object” આ મેસેજ દર્શાવવા માટે મેં puts મેથડ વ્યાખ્યિત કર્યું છે.

05:20 Next, I have defined Order dot new.

આગળ, મેં વ્યાખ્યિત કર્યું છે Order dot new.

05:24 This will invoke the initialize method.

આનાથી initialize મેથડ આવ્હાન થશે.

05:27 Switch to the terminal and type

terminal પર જાવ અને ટાઈપ કરો

05:31 ruby space object underscore initialize dot rb

ruby space object underscore initialize dot rb

05:36 and see the output.

અને આઉટપુટ જુઓ.

05:39 You will see the message “I have created an object” .

તમને “I have created an object” આ મેસેજ દેખાશે.

05:43 Now let us go back to gedit and add an argument to the method.

હવે ચાલો gedit પર જઈએ અને method (મેથડ) માં એક argument (આર્ગ્યુંમેંટ) ઉમેરીએ.

05:48 Let us modify the puts .

ચાલો puts માં સુધાર કરીએ.

05:51 It should display the value of the argument passed.

આ પસાર થયેલ argument ની વેલ્યુ દર્શાવવું જોઈએ.

05:55 Next let us type

આગળ ચાલો ટાઈપ કરીએ

05:56 Order dot new(“I have created an object”).

Order dot new(“I have created an object”) .

06:04 Here we have given an argument to the new method.

અહીં આપણે નવા મેથડને એક આર્ગ્યુંમેંટ આપી છે.

06:08 This argument gets passed on to the initialize method.

આ આર્ગ્યુંમેંટ initialize method પર પસાર થાય છે.

06:13 Switch to the terminal and type

ટર્મિનલ પર જાવ અને ટાઈપ કરો

06:16 ruby space object underscore initialize dot rb

ruby space object underscore initialize dot rb

06:20 and see the output.

અને આઉટપુટ જુઓ.

06:22 You will see the message “I have created an object” printed out.

તમને “I have created an object” આ મેસેજ પ્રીંટ થયેલ દેખાશે.

06:29 Now, you would have understood what object initialization means.

હવે, તમને object initialization નો અર્થ શું થાય છે તેની જાણ પડી ગઈ હશે.

06:33 Recall that in Ruby, methods are the functions that a class performs.

યાદ કરો કે Ruby માં methods એ એવા ફંક્શનો છે જેને class ભજવે છે.

06:39 Each method in a class is defined within the “def” and “end” block.

ક્લાસમાં આવેલ દરેક method ને “def” અને “end” બ્લોક અંતર્ગત વ્યાખ્યિત કરાય છે.

06:45 A multiword method name is separated with an underscore.

વધારે શબ્દ ધરાવતા method નામને underscore થી જુદું પાડવામાં આવે છે.

06:48 Some of the characters that can be appended to a method name are:

અમુક કેરેક્ટર જેને આપણે method નામ સાથે જોડાણ કરી શકીએ છીએ તે છે:

06:54  ? (question-mark)

 ? (question-mark)

06:56 = (equal to)

= (equal to)

06:58 Each of the characters add some meaning to the method.

દરેક કેરેક્ટર method ને અમુક અર્થ આપે છે.

07:02 Let us look at some examples.

ચાલો કેટલાક ઉદાહરણો તરફે જોઈએ.

07:05 Create a new file in gedit as shown in the basic level Ruby tutorials.

સામાન્ય સ્તરનાં Ruby ટ્યુટોરીયલમાં દર્શાવ્યા પ્રમાણે gedit માં એક નવી ફાઈલ બનાવો.

07:09 And name it class underscore methods dot rb.

અને તેને class underscore methods dot rb નામ આપો.

07:14 I have a working example of class methods code.

મારી પાસે class methods કોડનું કાર્યરત ઉદાહરણ છે.

07:17 You can pause the tutorial, and type the code as we go through it.

તમે ટ્યુટોરીયલ અટકાવીને કોડ ટાઈપ કરી શકો છો જેમ જેમ આપણે આગળ વધીશું.

07:21 Here I have defined a class named “Animal”.

અહીં મેં “Animal” નામનો ક્લાસ વ્યાખ્યિત કર્યો છે.

07:23 Then I have two methods “breathe” and “walk”.

ત્યારબાદ મારી પાસે બે મેથડો છે “breathe” અને “walk” .

07:28 They are both defined with the “def” and “end” keywords.

તે બંને “def” અને “end” કીવર્ડો વડે વ્યાખ્યિત કરાયા છે.

07:32 I have then initialized the object Animal.

ત્યારબાદ મેં object Animal ઈનીશલાઈઝ કર્યું છે.

07:36 I have assigned it to a variable called “animal” with lowercase “a”.

મેં તેને “animal” નામના વેરીએબલને એસાઈન કર્યું છે જેમાં “a” અક્ષર નાનો છે.

07:40 Then I have invoked the methods “breathe” and “walk” consequtively.

ત્યારબાદ મેં અનુક્રમે “breathe” અને “walk” મેથડો આવ્હાન કર્યા છે.

07:48 Now let us execute the program.

હવે ચાલો પ્રોગ્રામ એક્ઝીક્યુટ કરીએ.

07:51 Switch to the terminal and type

ટર્મિનલ પર જાવ અને ટાઈપ કરો

07:53 ruby space class underscore methods dot rb

ruby space class underscore methods dot rb

07:58 and see the output.

અને આઉટપુટ જુઓ.

08:00 You will notice the lines:

તમે જોશો કે આપેલ લાઈનો:

08:02 “ I breathe”

“ I breathe”

08:03 “ I walk”

“ I walk”

08:04 printed out.

પ્રીંટ થયેલી છે.

08:05 This is because you have invoked the two methods “breathe” and “walk”.

આ એટલા માટે કારણ કે તમે “breathe” અને “walk” આ બંને મેથડોને આવ્હાન કર્યા છે.

08:10 A “puts” statement defined within these methods gives the results you see.

આ મેથડો અંતર્ગત વ્યાખ્યિત થયેલ “puts” સ્ટેટમેંટ તમે જોયેલ પરિણામ આપે છે.

08:16 Next, let us look at how to create methods with a trailing question mark.

આગળ, ચાલો જોઈએ કે પાછળ જોડેલા question mark સહીત મેથડો કેવી રીતે બનાવવા.

08:21 Create a new file in gedit as shown in the basic level Ruby tutorials.

સામાન્ય સ્તરનાં Ruby ટ્યુટોરીયલમાં દર્શાવ્યા પ્રમાણે gedit માં એક નવી ફાઈલ બનાવો.

08:25 And name it class underscore methods underscore with underscore trailing underscore characters dot rb

અને તેને નામ આપો class underscore methods underscore with underscore trailing underscore characters dot rb

08:35 I have a working example of class methods with question mark code.

મારી પાસે question mark કોડ સહીત class methods નું કાર્યરત ઉદાહરણ છે.

08:40 You can pause the tutorial, and type the code as we go through it.

તમે ટ્યુટોરીયલ અટકાવીને કોડ ટાઈપ કરી શકો છો જેમ જેમ આપણે આગળ વધીશું.

08:45 Here I have taken the same class as before as an example.

અહીં મેં ઉદાહરણ તરીકે પહેલાની જેમ જ સમાન ક્લાસ લીધો છે.

08:48 Here the breathe method has a trailing “question mark (?)”.

અહીં breathe method પાછળ જોડાણ કરેલ “question mark (?)” ધરાવે છે.

08:52 Such methods are generally used to return boolean values.


આવા મેથાડો સામાન્ય રીતે boolean values પર્તાવવા માટે વપરાય છે.

08:55 This is based on the method naming convention of Ruby.

આ રૂબીનાં method નામકરણ રુપાંતરણ પર આધારિત છે.

09:00 The method gets invoked by declaring animal dot breathe question-mark

મેથડ animal dot breathe question-mark ડીકલેર કરવાથી આવ્હાન થાય છે.

09:06 Switch to the terminal and type

ટર્મિનલ પર જાવ અને ટાઈપ કરો

09:09 ruby space class underscore methods underscore with underscore trailing underscore characters dot rb and see the output.

ruby space class underscore methods underscore with underscore trailing underscore characters dot rb અને આઉટપુટ જુઓ.

09:22 You will notice the output as : “true”


તમને આઉટપુટ “true” તરીકે દેખાશે

09:26 Next, let us define another method called “walk”.

આગળ, ચાલો “walk” નામનું બીજું એક મેથડ વ્યાખ્યિત કરીએ.

09:30 Let us place an equal-to sign “=(value)” beside it.

ચાલો તેની બાજુમાં equal-to sign “=(value)” મુકીએ.

09:36 Let us invoke this method by calling animal dot walk.

ચાલો animal dot walk બોલાવીને આ મેથડ આવ્હાન કરીએ.

09:41 Then let us execute this method.

ત્યારબાદ ચાલો આ મેથડને એક્ઝીક્યુટ કરીએ.

09:44 Switch to the terminal and type

ટર્મિનલ પર જાવ અને ટાઈપ કરો

09:45 ruby class underscore methods underscore with underscore trailing underscore characters dot rb

ruby class underscore methods underscore with underscore trailing underscore characters dot rb

09:52 and see the output.

અને આઉટપુટ જુઓ.

09:56 It will give an “undefined method” error.

તે એક “undefined method” એરર આપશે.

09:59 This is because the equal to sign has another meaning.

આ એટલા માટે કારણ કે equal to sign નો જુદો જ અર્થ છે.

10:03 It is used to assign a value to a method.

આનો ઉપયોગ method ને વેલ્યુ એસાઈન કરવા માટે થાય છે.

10:08 So, let us invoke the method a little differently this time.

તો, ચાલો આ વખતે મેથડને સેજ જુદી રીતે આવ્હાન કરીએ.

10:13 Type puts animal dot walk equal to “ hops”

ટાઈપ કરો puts animal dot walk equal to “ hops”

10:17 Now let give it another try.

હવે ચાલો તેને બીજો એક અવસર આપીએ.

10:20 Switch to the terminal and run the command like before and see the output.

ટર્મિનલ પર જાવ અને પહેલાની જેમ જ આદેશ રન કરો અને આઉટપુટ જુઓ.

10:27 You will notice that the word “hops” get printed.

તમે જોશો કે શબ્દ “hops” પ્રીંટ થાય છે.

10:30 This demonstrates that the equal to sign next to a method means assignment.

આ ડેમોનસ્ટ્રેટ કરે છે કે મેથડ પછી આવેલ equal to sign એટલે કે એસાઈનમેંટ.

10:36 Now you should be able to write your own methods.

હવે તમે પોતાના મેથડો લખતા શીખી ગયા હોવા જોઈએ.

10:42 In this tutorial we have learnt-

આ ટ્યુટોરીયલમાં આપણે શીખ્યા-

10:44 How to declare classes

classes કેવી રીતે ડીકલેર કરવા

10:46 How to create objects of a class

class નાં objects કેવી રીતે બનાવવા

10:48 Different ways of defining methods in Ruby

રૂબીમાં methods વ્યાખ્યિત કરવાનાં વિવિધ માર્ગો.

10:52 As an assignment:

એસાઈનમેંટ તરીકે:

10:54 Define a class Product

એક class Product વ્યાખ્યિત કરો.

10:56 Define methods that you can use to get values of “myvar” and set values for “myvar”.

“myvar” ની વેલ્યુઓ મેળવવા અને “myvar” માટે વેલ્યુઓ સુયોજિત કરવા માટે તમે વાપરી શકો એવા methods વ્યાખ્યિત કરો.

11:01 To set values, define the method using “=” sign.

વેલ્યુઓ સુયોજિત કરવા માટે, 'method ને “=” ચિન્હ વાપરીને વ્યાખ્યિત કરો.

11:05 Instantiate the object of the class and set and get values using the above 2 methods.

ક્લાસ અને સેટનાં ઓબજેક્ટને ઇન્સ્ટન્ટીએટ કરો અને ઉપર આપેલ બે મેથડો વાપરીને વેલ્યુઓ મેળવો.

11:12 Watch the video available at the following link.

આપેલ લીંક પર ઉપલબ્ધ વિડીયો નિહાળો.

11:14 It summarises the Spoken Tutorial project.

તે સ્પોકન ટ્યુટોરીયલ પ્રોજેક્ટનો સારાંશ આપે છે.

11:18 If you do not have good bandwidth, you can download and watch it.

જો તમારી પાસે સારી બેન્ડવિડ્થ ન હોય તો, તમે વિડીયો ડાઉનલોડ કરીને જોઈ શકો છો.

11:22 The Spoken Tutorial Project Team :

સ્પોકન ટ્યુટોરીયલ પ્રોજેક્ટ ટીમ:

11:24 Conducts workshops using spoken tutorials

સ્પોકન ટ્યુટોરીયલોનાં ઉપયોગથી વર્કશોપોનું આયોજન કરે છે.

11:27 Gives certificates to those who pass an online test

જેઓ ઓનલાઈન પરીક્ષા પાસ કરે છે તેઓને પ્રમાણપત્રો આપે છે.

11:30 For more details, please write to contact@spoken-tutorial.org

વધુ વિગતો માટે, કૃપા કરી contact@spoken-tutorial.org પર લખો.

11:36 Spoken Tutorial Project is a part of the Talk to a Teacher project.

સ્પોકન ટ્યુટોરીયલ પ્રોજેક્ટ ટોક ટુ અ ટીચર પ્રોજેક્ટનો એક ભાગ છે.

11:39 It is supported by the National Mission on Education through ICT, MHRD, Government of India.

જેને આઈસીટી, એમએચઆરડી, ભારત સરકાર મારફતે શિક્ષણ પર નેશનલ મિશન દ્વારા આધાર અપાયેલ છે.

11:46 More information on this Mission is available at spoken hyphen tutorial dot org slash NMEICT hyphen Intro

આ મિશન પર વધુ માહિતી આ લીંક પર ઉપલબ્ધ છે http://spoken-tutorial.org/NMEICT-Intro.

11:56 This is Anjana Nair signing off. Thank you

IIT Bombay તરફથી હું, જ્યોતી સોલંકી વિદાય લઉં છું. અમને જોડાવાબદ્દલ આભાર.

Contributors and Content Editors

Jyotisolanki, PoojaMoolya