Archive for July, 2008

Visibility of a method

By default methods within a class in Ruby is PUBLIC. But as we know, ruby supports meta programming and hence a new/updated code can be generated on fly during the runtime.
here is a way to make the public class methods to private.

class Myclass
  def mymethod
    puts "I am public and wishing to be private!"
  end
  private :mymethod
  # OR also can be written as
  # private_class_method :mymethod
end

obj = Myclass.new
obj.mymethod
# private method `mymethod' called for # (NoMethodError)

Similary public :mymethod or public_class_method :mymethod


Add comment July 3, 2008

Regular expression

Here is the most frequently used special characters in regular expression of Java script. In a simple and concise way. [Background support : AMIT R.]

*   - 0/n chars >> /raj*/ -> ra, raj,rajj,rajesh, krajesh too [talking about j]
+   - 1/n chars >> /raj=/ -> raj,rajesh, krajesh too but not ra [talking about j]
?   - 0/1 char  >> /raj?/ -> ra, raj, rajj [talking about j]
.   - any SINGLE char expecting at its postion except \n.  [no previous no after]
    /.n/ >> in,on,an but not nan
|  - or >> /java|ruby/  -> java or ruby (dont think a or r) , matches also jruby or rjava
[abc] - matches ANY ONE , same can be written as [a-c]
^   - begin with /^ruby/ -> ruby, ruby programmer but not jruby
$   - end with /ruby$/ -> End with y >> ruby, jruby, kruby but not rubyk
[^a-z]  - Any single match other than a-z
\d   /[0-9]/  i.e. any single digit
\D   /^[0-9]/ i.e. any single char other than 0 to
\w  - Any alphanumeric char other than underscore  [A-Za-Z0-9]

Add comment July 3, 2008


Categories

posts[:recent]

episodes[:recycled]

@@name = PRAYAS

Step down at my blog with your ideas,comments,suggestions on Ruby,RoR,Ajax or Web2.0.You may reach me at
infostall@gmail.com

find_by_tags

Links

visitors[:since_Mar'08]

free web counter

Spam Blocked

Feeds

Meta

RSS Prayas here