Thursday, August 30, 2012

Ruby Handbook (Frequently Used Concepts)

Frequently used concepts-
1. Difference between 'do..end' block and brackets { }.
Ans: Do End Block vs. Brackets

2. Copying Ruby object.
Ans: All variables in ruby are references to an object. a = b means that a and b points to the same object. To copy an object use a = b.dup . Credit

3. What is Ruby's double-colon (::) ?
Ans. Double color :: in Ruby

4. How to call Class Methods from Instance Methods? Difference between Class Methods and Instance Methods? Also the differences between class instances and method instances.
Ans: Using Modules and mixins. A mixin is a module, but a module isn't necessarily a mixin.
        a. Difference between class variables and instance variables
        b. Difference between class methods and instance methods

5. Ruby is not a statically typed language i.e. it is a dynamic language and there is no such thing called compile time check. That's why even if there is some conflict in accessing a method because of its Access Protection then it will be determined only at runtime without any prior warning.

6. In Ruby, all variable are references to objects not their copies.

7. What is the difference between puts and print method?
Ans: puts method add a new line character after each print however print method does not. So if you have a block to print all elements of  an array, then puts method will list each object of array in new line however puts will place all elements in single line like a string. Other references

8. Name a method which is used to get next int or character from a variable? i.e. to get 3 from a variable whose value is 2 or to get B from a variable A.
Ans: <variable>.succ (Successor)

9. Difference between Single Quote and Double Quotes in Ruby?
Ans: Mostly single quotes are used when we don't need to have string "interplation", where actually we use double quotes. Single Quote Vs Double Quote (Brief)

10. What are Exit codes in Ruby?
Ans: Whenever you run a Ruby script/program, a process is started. When a process is completed or interrupted in middle, it always exits with a exit code within range 0-255 which represents whether process was successful or not. An exit code with 0 means that program was successful. More details: Exit code in ruby

11. What is Database migration and list all methods used for the same
Ans. Migrations are a convenient way for you to alter your database in a structured and organized manner. Complete explanation: Migrations in ruby on rails

12. RubyMine - Could not find gem "jquery-rails". or similar gems
Ans. In such issues, run command gem install jquery-rails from the command line. Stackoverflow Adding a new gem

13. Scope of instance variable in a controller method. How long it will be retained?
Ans: 

Monday, August 27, 2012

Frequently used Adobe Reader keyboard shortcuts

These days I'm using Adobe Reader very frequently and extensively. Here are the couple of shortcuts which will help you in reading better.

1. Go to a particular page number: CTRL + SHIFT + N . So now no useless scrolling if you mistakenly pressed end key.
2. Readmode/ Presentation mode: CTRL + H, L: Personally I use CTRL + L mode for reading.
3. Increase/Decrease Zoom level: CTRL + "+ / - ": Control plus "+" or "-" key. Note that this shortcut also works in Presentation mode so if you want better concentration while reading a book and font of book in presentation mode (full screen mode) is very small then use CTRL + "+" key to increase that. I use it this way only.

Will add more later.

Saturday, August 25, 2012

Configuring RUBY in Eclipse Juno, Windows

Steps to configure Eclipse Juno for RUBY development from scratch on Windows 7:
1. Install Ruby: Download the latest ruby one-click installer and after installation. Run 'ruby -v' command to verify ruby path is properly set up. In case you get an error like- not recognized as an internal or external command. Add a new environment variable (right click my computers, properties, advanced properties, environment variable) with properties as : Name - Path , Value - Ruby bin directory path. Somewhat similar to C:\ruby193\bin
2. Download latest eclipse (preferably - Eclipse IDE for Java developers) from Link to download Eclipse.
3. Extract the zip file to a folder and create shortcut of eclipse.exe to an easily accessible place and run eclipse.
4. Now your eclipse is ready for Ruby installation. Go to Help -> Install New Software.
5. Select 'Juno' for Work with combobox.
6. Then in the textbox below 'Work with' combo, type "Ruby".
7. You will see a checkbox before 'Dynamic Languages Toolkit - Ruby development tools'
8. Select the check box and click next. Proceed to install the same.

There are the major steps you need to set up your development machine.

You might need to configure Interpreters for ruby (which is done by default) In case you face issue with creating new ruby project then go to 'Window -> Preferences -> Ruby -> Interpreters' in eclipse. See if there is a ruby.exe interpreter is selected. In case it is not then add a new interpreter. Click browse and provide ruby.exe path. Most probably it will be C:\ruby193\bin. There after it should run successfully.

Now I've started using RubyMine for ruby development. Though it is paid but a very good environment for ruby development.

Sources: Searched a lot but this was the one which finally helped me in configuring interpreter Setting up your environment

Friday, August 24, 2012

Writing your first RUBY program

So finally I've started learning a language which does not have any main method (starting method). Yes, it's ruby. Though I learned a foundation knowledge about ruby and its syntax and familiarize with couple of programs. Here is what you can do to write and run your first ruby program.
1. Online code compiler and editor: Compilr
2. Writing first ruby program : this finally helped me to write first offline program on my machine.
3. Setting up your machine : Setting Rails Development Environment
Configuring your machine to learn new language is also imp step in learning specially when you've no idea about the subject. Currently I'm exploring the text editor (kind of IDE) for Ruby and will post when found a good one and ofcourse free. :)

Also I find this book quite good for beginners Programming Ruby : The Pragmatic Guide