Roshan Book

My Tech Notebook

Category Archives: Blog

Learning Ruby Part 10 Decision Making

== –> It compares values

!= – > If not equal to

< – > less than

<= – > less than equal to

> = –> greater than equal to

> –> greater than

&& – > When you want to test more than one conditions

Advertisements

Learning Ruby Part 9 Expressions

E.g

a=3

b=6

a+b

It gives 9

Assigning value of variable to variable

d=33

f=d

Now if we change value of d to 3, f still has value 33.

Shorthands

g=68

g=g+20

 

Same thing could be written as

g+=12

Same thing could be done with –, *, /

Learning Ruby Part 8–Variables

We can create Methods that don’t belong to any class.

Declaring a common method

def crap

puts “I am a crappy crap”

end

Calling Method directly

crap

 

Adding value to variable

man=”manish”

 

Few things to keep in mind

A variable should start with letters or _ .

No spaces allowed

No symbols like %

Variables are case sensitive

Learning Ruby Part 7–Strings

String means bunch of text like “my name is manish”

 

Declaring a string

My name is Manish

Methods of Strings

.length  – >Returns number of characters. It includes space

.upcase –> Converts everything to uppercase

+ –> It adds two strings

.reverse-> It reverse the strings

.reverse.upcae – > Here we added two methods for a string. It will reverse and change string to uppercase

Full list of string methods can be found here

Learning Ruby Part 6–Argument

Learning Ruby Part 5–More on Objects

In Ruby every thing is an Object.

When we write 12, it is actually an object of class called FixNum.

To find out what class objects belong to, use

.class

Method

 

Kernel methods are common methods,which any class can used.

Some examples of Kernel methods

puts

print

For kernel methods, we can directly write it, without mentioning class.

Learning Ruby Part 4–Methods

Methods are something which Objects do.

Defining a Method

class Manish
def talk
puts "Hi, my name is Manish"
end
end

 

Notice the two ends. One end , ends method and other one ends class. Now we have a class Manish having a Method Talk.

 

Calling Method

man=Manish.new
man.talk

Objects are characteristics of Class and Methods are what Classes do.

Learning Ruby Part 3 – Inheritance

Inheritance is simply copying all the attributes from a base class to new class. It will save you lots of typing.

E.g

class Animal

attr_accessor :name, :age , :trait

end

This is how we declare a base class

class Dog < Animal

end

And this is how Dog class copies attributes from base class Animal. Now Dog has same attributes as Animal.

Adding Additional Attributes

Suppose you want to add extra attribute called type, declare Dog class like below

class Dog < Animal

attr_accessor :type

end

And now we have added attribute to Dog class, which is not in Base class “Animal”

 

Add complete read write access in Ubuntu

What is the Remote Posting URL

Windows live writer is a great tool to publish on wordpress/typepad/blogger etc. While configuring windows live writer for my wordpress site manishroshan.com, a point came when they asked for

Remote Posting URL in the format http://<hostname>/<wp_path>/xmlrpc.php

 

Now to get passed that you need to follow two steps

 

Step 1. Go to wordpress cms>>Settings>>Writing and enable Atom publishing protocol and XML-RPC

Step 2. For remote posting url , use following format

http://manishroshan.com/xmlrpc.php

If wordpress is at root. Add folder location after manishroshan.com/ if that wordpress is installed in a folder.

 

%d bloggers like this: