Archive for May, 2007

Ruby Characters to ASCII

This piece of code converts Ruby Characters to ASCII code and vice versa.


Comments

Slice Ruby String

These are different ways to divide or slice ruby string. All of these statements gives the same output.


Comments

Ruby String successor

This is a simple example that shows how ruby string successor works.


Comments

Email validation using ruby

The following piece of code validates any email that ends with .com, .edu, .org or any three letter extension. It uses regular expressions to find a match.


Comments (6)

Reverse Ruby String Words

In my last post, i gave a simple snippet to reverse ruby string. Here, I am giving simple snippet to reverse ruby string words. So, given string like “ruby on rails”, the output going to be “rails on ruby”.

Comments (3)

Reverse Ruby String

This how we reverse entire string in ruby :

To reverse ruby string words, check this link.

Comments

Insert into Ruby Array

The following piece of code insert to each hash in the array a new element. I used destructive hash merge to add the new element to each hash in the array.

Comments (3)

Ruby Array Map or collect

You can process every element in Ruby array using a loop or you may use ruby Array map or collect (Map and Collect are different names for same function). The Second and fourth print statements in the next example will print [2, 3, 4, 5, 6]. The functions that end with ! will modify the original array itself since it is destructive. The first and third will print the array [1, 2, 3, 4, 5] since the method map or collect did not change the array itself (it did not end with !)

Comments

Rails makes SEO easier

Rails is one of the best frameworks for Search Engine optimization (SEO), at least if I compare it with frameworks I know about it. If you are not familiar with SEO, SEO is the process of optimizing the site for the sake of gaining more traffic from search engines.

I will post in details later about SEO. For now, if you are looking to SEO a site, you must at least make sure that your site can be crawled by search engine spiders. The following are examples of sites that spider can not crawl:

1) Site that is hidden behind a web form.
2) Site that uses 3 or more query parameters (very important for GoogleBot, its quite not problem for Yahoo Slurp).

Search engines can not submit forms and they feel scary from URL that has 3 or more query parameters since they may crawl large number of pages with the same content with different query parameters.

Furthermore, Rails do not use Sessions as parameter in the URL dislike most J2EE servers and Apache for users who have cookie disabled like Spiders. Having URL indexed with session make the search engines wondering if this URL will be render the same page that they crawled when the user click on it in their result page. They may feel that the session existence will render different page based on geographic location or language locale. Thus, Rails does not use sessions saved in URL and thats another cool feature for SEO.

Rails make it easy to build your user and search engine friendly. I have done a little SEO (mainly in keyworded URLs aspect) work in J2EE and in PHP, I found Rails far better in doing that job.

All what you need to do is to point URLs which can be represented using a string or regular expression. It is so easy to build search engine and user friendly URLs which is usually vitual.

Thus, Ruby on Rails helps you to create a search engine friendly site. However, do not forget that having SE friendly URL is not everything in SEO, you need to consider having the best title tag, meta tags, headers (h1, h2, h3, etc.), styles, internal linking, breadcrumb, external linking, site map, XML feeds, rich text pages, no spelling errors, avoid HTML bugs (specially in nested tables), keyword research and many more.

If you have question regarding SEO, feel free to ask and I will do my best to answer you.

To learn more about Search engine Optimization, I would recommend you to read Los Angeles Search Engine Optimization Services. The blog describes SEO process step by step.

Comments (1)

Introducing Ruby Array

1) Ruby Array is collection of objects that do not need to be the same type. That means, ruby array class can hold Fixnum, float, string, etc objects in the same array. The following peace of code:

Will return
Fixnum
Float
String
Array
=> [1, 1.2, "2", [1, 2, 4]]

2) Ruby arrays can be concatenated using + sign, for example

arr3 will be [1, 2, 3, 4]

3) Ruby array is quite circular. Ruby Array allows reverse index; negative index.

The previous peace of code going to return 6 which is located at index = -1.

4) Ruby Array has the following methods

& * + - << <=> == [] [] []= abbrev assoc at clear collect collect! compact compact! concat dclone delete delete_at delete_if each each_index empty? eql? fetch fill first flatten flatten! frozen? hash include? index indexes indices initialize_copy insert inspect join last length map map! new nitems pack pop pretty_print pretty_print_cycle push quote rassoc reject reject! replace reverse reverse! reverse_each rindex select shift size slice slice! sort sort! to_a to_ary to_s to_yaml transpose uniq uniq! unshift values_at yaml_initialize zip |

Comments

« Previous entries · Next entries »