Author: admin
-
Ruby Socket Programming
Sockets are the end points of a network communication channel, where client and server communicate to each other. They can communicate either on same machine or on different machines. Types of socket: There are two levels of socket, high and low. Low level access allows you to work on sockets that are supported by your…
-
Ruby Regular Expression
A regular expression is also spelled as regexp which holds a regular expression, used to match a pattern against strings. In Ruby, a pattern is written between forward slash characters. They describe the content of a string. Ruby regular expression is more similar to Perl regular expression. Syntax: Ruby 1.9 uses Oniguruma regular expressions library but Ruby 2.0 uses Onigmo regular…
-
Ruby OOPs Concept
Ruby is a true object oriented language which can be embedded into Hypertext Markup Language. Everything in Ruby is an object. All the numbers, strings or even class is an object. The whole Ruby language is basically built on the concepts of object and data. OOPs is a programming concept that uses objects and their…
-
Ruby Exceptions
Ruby exception is an object, an instance of the class Exception or descendent of that class. It represents some exceptional condition. In a Ruby program, when something goes wrong, it throws an exceptional behavior. By default Ruby program terminates on throwing an exception. We can declare some exception handlers within Ruby. An exception handler is…
-
Ruby Directories
Class Dir has directory streams as objects which represents directories in underlying file system. Directories are handled with Dir class. Creating a Directory To create a directory mkdir command is used. You can give permission to a directory if you want. Syntax: Example: We have created a directory “project” in out system. Checking a Directory…
-
Ruby Iterators
Iterator is a concept used in object-oriented language. Iteration means doing one thing many times like a loop. The loop method is the simplest iterator. They return all the elements from a collection, one after the other. Arrays and hashes come in the category of collection. Ruby Each Iterator The Ruby each iterator returns all…
-
Ruby Ranges
Ruby range represents a set of values with a beginning and an end. They can be constructed using s..e and s…e literals or with ::new. The ranges which has .. in them, run from beginning to end inclusively. The ranges which has … in them, run exclusively the end value. Output: Ruby has a variety of ways to define ranges.…
-
Ruby Hashes
A Ruby hash is a collection of unique keys and their values. They are similar to arrays but array use integer as an index and hash use any object type. They are also called associative arrays, dictionaries or maps. If a hash is accessed with a key that does not exist, the method will return…
-
Ruby Strings
Ruby string object holds and manipulates an arbitary sequence of bytes, typically representing characters. They are created using String::new or as literals. Quotes Ruby string literals are enclosed within single and double quotes. Example: Output: Accessing string elements You can access Ruby string elements in different parts with the help of square brackets []. Within square brackets…
-
Ruby Modules
Ruby module is a collection of methods and constants. A module method may be instance method or module method. Instance methods are methods in a class when module is included. Module methods may be called without creating an encapsulating object while instance methods may not. They are similar to classes as they hold a collection…