Ruby/C3/Object-Oriented-Concept-in-Ruby/Kannada
From Script | Spoken-Tutorial
Revision as of 17:43, 19 January 2016 by Sandhya.np14 (Talk | contribs)
| Time | Narration |
| 00:01 | Ruby ಯಲ್ಲಿ Object Oriented Concept (ಆಬ್ಜೆಕ್ಟ್ ಓರಿಯಂಟೆಡ್ ಕಾನ್ಸೆಪ್ಟ್) ಎಂಬ 'ಸ್ಪೋಕನ್ ಟ್ಯುಟೋರಿಯಲ್' ಗೆ ನಿಮಗೆ ಸ್ವಾಗತ. |
| 00:06 | ಈ ಟ್ಯುಟೋರಿಯಲ್ ನಲ್ಲಿ ನಾವು: |
| 00:08 | * 'ಕ್ಲಾಸ್'ಗಳನ್ನು ಬಳಸುವುದು |
| 00:09 | * 'ಆಬ್ಜೆಕ್ಟ್' ಗಳನ್ನು ಕ್ರಿಯೇಟ್ ಮಾಡುವುದು |
| 00:10 | * 'Ruby'ಯಲ್ಲಿ 'ಮೆಥಡ್'ಗಳನ್ನು ಡಿಫೈನ್ ಮಾಡುವ ವಿಭಿನ್ನ ರೀತಿಗಳು ಇವುಗಳನ್ನು ಕಲಿಯುವೆವು. |
| 00:13 | ಇಲ್ಲಿ ನಾವು: |
| 00:14 | * Ubuntu ಆವೃತ್ತಿ 12.04 |
| 00:16 | * Ruby 1.9.3 ಇವುಗಳನ್ನು ಬಳಸುತ್ತಿದ್ದೇವೆ. |
| 00:19 | ಈ ಟ್ಯುಟೋರಿಯಲ್ ಅನ್ನು ಅನುಸರಿಸಲು, 'Linux' ಕಮಾಂಡ್ ಗಳು, ‘ಟರ್ಮಿನಲ್’ ಮತ್ತು 'ಟೆಕ್ಸ್ಟ್-ಎಡಿಟರ್' ಗಳನ್ನು ನೀವು ತಿಳಿದಿರಬೇಕು. |
| 00:24 | ಇಲ್ಲದಿದ್ದರೆ, ಸಂಬಂಧಿತ ಟ್ಯುಟೋರಿಯಲ್ ಗಳಿಗಾಗಿ ದಯವಿಟ್ಟು ನಮ್ಮ ವೆಬ್ಸೈಟ್ ಗೆ ಭೆಟ್ಟಿಕೊಡಿ. |
| 00:28 | ಪ್ರಾರಂಭಿಸುವ ಮುನ್ನ, “ttt” ಎಂಬ ಡಿರೆಕ್ಟರೀಯನ್ನು ಈಮೊದಲು ನಾವು ಕ್ರಿಯೇಟ್ ಮಾಡಿದ್ದೆವು ಎಂಬುದನ್ನು ನೆನಪಿಸಿಕೊಳ್ಳಿ. |
| 00:33 | ನಾವು ಆ ಡಿರೆಕ್ಟರೀಗೆ, |
| 00:35 | 'ruby hyphen tutorial' ಮತ್ತು 'classes' ಡಿರೆಕ್ಟರೀಗಳಿಗೆ ಹೋಗೋಣ. |
| 00:41 | 'Ruby' (ರೂಬಿ), ಒಂದು ಆಬ್ಜೆಕ್ಟ್ ಓರಿಯಂಟೆಡ್ ಭಾಷೆಯಾಗಿದೆ. |
| 00:44 | 'Ruby'ಯಲ್ಲಿ ವ್ಯಾಲ್ಯೂ, ಸ್ಟ್ರಿಂಗ್ ಅಥವಾ ಸಂಖ್ಯೆ ಎಲ್ಲವೂ ಆಬ್ಜೆಕ್ಟ್ ಗಳಾಗಿವೆ. |
| 00:49 | 'ಕ್ಲಾಸ್' (class), ಸಂಬಂಧಿತ ಡೇಟಾ ಮತ್ತು ಫಂಕ್ಷನ್ ಗಳ ಒಂದು ಸಂಗ್ರಹವಾಗಿದೆ. |
| 00:53 | ಇದು ಮಾಹಿತಿಯನ್ನು ವ್ಯವಸ್ಠಿತವಾಗಿ ಇಡಲು ಸಹಾಯಮಾಡುತ್ತದೆ. |
| 00:56 | ಆಬ್ಜೆಕ್ಟ್, 'ಕ್ಲಾಸ್'ನ ಒಂದು ನಿದರ್ಶನವಾಗಿದೆ. |
| 01:00 | 'ಕ್ಲಾಸ್'ನ ವ್ಯಾಖ್ಯಾನವು (definition), 'class' ಎಂಬ ಕೀವರ್ಡ್ ನಿಂದ ಆರಂಭವಾಗುತ್ತದೆ. |
| 01:05 | ಇದರ ನಂತರ 'ಕ್ಲಾಸ್'ನ ಹೆಸರು (class name) ಇರುತ್ತದೆ. |
| 01:08 | ಇದು “end” ನಿಂದ ಕೊನೆಗೊಳ್ಳುತ್ತದೆ. |
| 01:11 | ನಾವು class ನ ಒಂದು ಉದಾಹರಣೆಯನ್ನು ನೋಡೋಣ. |
| 01:14 | class Product |
| 01:16 | ruby code |
| 01:17 | end |
| 01:20 | 'ಕ್ಲಾಸ್'ನ ಹೆಸರು ದೊಡ್ಡಕ್ಷರದಿಂದಲೇ ಆರಂಭವಾಗಬೇಕು. |
| 01:24 | ಒಂದಕ್ಕಿಂತ ಹೆಚ್ಚು ಶಬ್ದಗಳನ್ನು ಹೊಂದಿರುವ ಹೆಸರುಗಳು ’ಕ್ಯಾಮಲ್ ಕೇಸ್’ (camelcase) ನಲ್ಲಿ ಇರಬೇಕು. |
| 01:28 | ಉದಾಹರಣೆಗೆ, |
| 01:30 | 'UserInformation' |
| 01:32 | 'ProductInformation' |
| 01:34 | ಅನಂತರದ ಫೈಲ್ ನ ಹೆಸರುಗಳು, ಶಬ್ದಗಳನ್ನು ಬೇರ್ಪಡಿಸಲು 'ಅಂಡರ್ಸ್ಕೋರ್'ಅನ್ನು ಹೊಂದಿರುವುವು: |
| 01:37 | 'user underscore information' (ಯೂಸರ್ ಅಂಡರ್ಸ್ಕೋರ್ ಇನ್ಫರ್ಮೇಶನ್) |
| 01:40 | 'product underscore information' (ಪ್ರೊಡಕ್ಟ್ ಅಂಡರ್ಸ್ಕೋರ್ ಇನ್ಫರ್ಮೇಶನ್) |
| 01:45 | ಪ್ರಾಥಮಿಕ ಹಂತದ 'Ruby tutorials'ನಲ್ಲಿ ತೋರಿಸಿದಂತೆ 'gedit'ನಲ್ಲಿ ಒಂದು ಹೊಸ ಫೈಲನ್ನು ಕ್ರಿಯೇಟ್ ಮಾಡಿ. |
| 01:48 | ಅದನ್ನು "class_definition.rb" ಎಂದು ಹೆಸರಿಸಿ. |
| 01:52 | ನನ್ನ ಹತ್ತಿರ 'classes' (ಕ್ಲಾಸಸ್)ಅನ್ನು ಜಾರಿಗೊಳಿಸುವ ಒಂದು ಉದಾಹರಣೆಯಿದೆ. |
| 01:57 | ನಾವು ಇದರಲ್ಲಿ ಮುಂದುವರಿಯುತ್ತಿದ್ದಂತೆ, ನೀವು ಟ್ಯುಟೋರಿಯಲ್ ಅನ್ನು ನಿಲ್ಲಿಸಿ ಕೋಡ್ ಅನ್ನು ಟೈಪ್ ಮಾಡಬಹುದು. |
| 02:02 | ಈ ಉದಾಹರಣೆಯಲ್ಲಿ, ನಾನು 'Order' ಎಂಬ ಹೆಸರಿನ ಒಂದು 'class' (ಕ್ಲಾಸ್)ಅನ್ನು ಡಿಫೈನ್ ಮಾಡಿದ್ದೇನೆ. |
| 02:05 | ಈಗ, ನಾವು ಕೆಲವು ವೇರಿಯೇಬಲ್ ಗಳನ್ನು ಸೇರಿಸಿ ಕ್ಲಾಸ್ ಅನ್ನು ಉಪಯುಕ್ತಗೊಳಿಸೋಣ. |
| 02:11 | ಆಮೇಲೆ ನಾನು “myinstance” ಎಂಬ ಒಂದು ಇನ್ಸ್ಟನ್ಸ್ ವೇರಿಯೇಬಲ್ ಅನ್ನು ಡಿಫೈನ್ ಮಾಡಿದ್ದೇನೆ |
| 02:15 | ಹಾಗೂ ಅದಕ್ಕೆ ಒಂದು ವ್ಯಾಲ್ಯೂಅನ್ನು ಅಸೈನ್ ಮಾಡಿದ್ದೇನೆ. |
| 02:18 | ನಾನು “myclassvar” ಎಂಬ ಒಂದು ಕ್ಲಾಸ್-ವೇರಿಯೇಬಲ್ ಅನ್ನು ಸಹ ಡಿಫೈನ್ ಮಾಡಿದ್ದೇನೆ |
| 02:21 | ಹಾಗೂ ಅದಕ್ಕೆ ಒಂದು ವ್ಯಾಲ್ಯೂಅನ್ನು ಅಸೈನ್ ಮಾಡಿದ್ದೇನೆ. |
| 02:24 | ಈಗ, ಈ 'class'ಅನ್ನು ಉಪಯೋಗಿಸುವ ಸ್ವಲ್ಪ ಕೋಡ್ ಅನ್ನು ನಾವು ಸೇರಿಸೋಣ. |
| 02:30 | ಹೀಗೆ ಟೈಪ್ ಮಾಡಿ: puts Order dot instance underscore variables |
| 02:36 | ಈ ಸಾಲಿನ ಮೊದಲು, 'puts' ಕೆಲವು ಅಕ್ಷರಗಳು ಹೊಸ ಪಂಕ್ತಿಗಾಗಿ ಸ್ಲ್ಯಾಶ್ '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 | Next, let us look at what an object is. |
| 03:40 | An object is an instance of a class. |
| 03:43 | Which means, an object is created from a class. |
| 03:46 | An object will have the properties and methods defined in the class. |
| 03:52 | How do you declare an object? |
| 03:54 | We declare an object of a class using the "new" keyword. |
| 03:58 | Here, we are declaring an object of the Product class. |
| 04:02 | Here, an object gets created. |
| 04:05 | product = Product.new |
| 04:09 | This process is called initialization of an object. |
| 04:12 | This object is of type : Product. |
| 04:16 | Now, let is look at what an “initialize” method is. |
| 04:20 | An initialize method is called at the time of object creation. |
| 04:26 | On calling new on an object, we invoke the initialize method. |
| 04:31 | An initialize method may take a list of parameters. |
| 04:37 | Like other Ruby methods, it is preceded by the “def” keyword. |
| 04:43 | Let us look at an example. |
| 04:46 | Create a new file in gedit as shown in the basic level Ruby tutorials. |
| 04:50 | And name it object undescore initialize dot rb. |
| 04:55 | I have a working example of the object initialization code. |
| 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” . |
| 05:08 | Then I have defined the initialize method, with no argument. |
| 05:13 | I have defined a 'puts' method to display the message: “I have created an object”. |
| 05:20 | Next, I have defined Order dot new. |
| 05:24 | This will invoke the initialize method. |
| 05:27 | Switch to the terminal and type: |
| 05:31 | 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”. |
| 05:43 | Now, let us go back to gedit and add an argument to the method. |
| 05:48 | Let us modify the puts. |
| 05:51 | It should display the value of the argument passed. |
| 05:55 | Next, let us type: |
| 05:56 | 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. |
| 06:13 | Switch to the terminal and type: |
| 06:16 | 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. |
| 06:29 | Now, you would have understood what object initialization means. |
| 06:33 | Recall that in Ruby, methods are the functions that a class performs. |
| 06:39 | Each method in a class is defined within the “def” and “end” block. |
| 06:45 | A multiword method-name is separated with an underscore. |
| 06:48 | Some of the characters that can be appended to a method name are: |
| 06:54 | '?' (question-mark) |
| 06:56 | '=' (equal to). |
| 06:58 | Each of the characters add some meaning to the 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. |
| 07:09 | And name it: class underscore methods dot rb. |
| 07:14 | I have a working example of class methods code. |
| 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”. |
| 07:23 | Then I have two methods- “breathe” and “walk”. |
| 07:28 | They are both defined with the “def” and “end” keywords. |
| 07:32 | I have then initialized the object Animal. |
| 07:36 | I have assigned it to a variable called “animal” with lowercase “a”. |
| 07:40 | Then I have invoked the methods “breathe” and “walk” consecutively. |
| 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 |
| 07:58 | and see the output. |
| 08:00 | You will notice the lines: |
| 08:02 | “ I breathe” |
| 08:03 | “I walk” |
| 08:04 | printed out. |
| 08:05 | This is because you have invoked the two methods “breathe” and “walk”. |
| 08:10 | A “puts” statement defined within these methods gives the results you see. |
| 08:16 | Next, let us look at how to create methods with a trailing question mark. |
| 08:21 | Create a new file in gedit as shown in the basic level Ruby tutorials. |
| 08:25 | And name it 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. |
| 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 (?). |
| 08:52 | Such methods are generally used to return boolean values. |
| 08:55 | This is based on the method naming convention of Ruby. |
| 09:00 | The method gets invoked by declaring 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. |
| 09:22 | You will notice the output as : “true” |
| 09:26 | Next, let us define another method called “walk”. |
| 09:30 | Let us place an equal-to sign “=(value)” beside it. |
| 09:36 | Let us invoke this method by calling 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 |
| 09:52 | and see the output. |
| 09:56 | It will give an “undefined method” error. |
| 09:59 | This is because the equal to sign has another meaning. |
| 10:03 | It is used to assign a value to a method. |
| 10:08 | So, let us invoke the method a little differently this time. |
| 10:13 | Type: puts animal dot walk equal to “ hops” . |
| 10:17 | Now, let us 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. |
| 10:30 | This demonstrates that the equal to sign next to a method means assignment. |
| 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 |
| 10:46 | * How to create objects of a class |
| 10:48 | * Different ways of defining methods in Ruby. |
| 10:52 | As an assignment: |
| 10:54 | Define a class Product |
| 10:56 | Define methods that you can use to get values of “myvar” and set values for “myvar”. |
| 11:01 | To set values, define the method using “=” sign. |
| 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 summarizes 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 |
| 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. |
| 11:56 | This is Anjana Nair, signing off. Thank you. |