Jumat, 13 Juli 2018

Sponsored Links

WHY WE SHOULD KNOW ABOUT RUBY PROGRAMMING LANGUAGE??? - TECH-GEEKS
src: tec4talk.com

Ruby is a dynamic, interpreted, reflective, object-oriented, and common programming language. It was designed and developed in the mid-1990s by Yukihiro "Matz" Matsumoto in Japan.

According to the creator, Ruby is influenced by Perl, Smalltalk, Eiffel, Ada, and Lisp. It supports several programming paradigms, including functional, object-oriented, and imperative. It also has a dynamic type system and automatic memory management.


Video Ruby (programming language)



Histori

Konsep awal

Matsumoto said that Ruby was conceived in 1993. In a 1999 post to the ruby-talk mailing list he explained some initial ideas about the language:

I'm talking to my colleagues about the possibility of an object-oriented scripting language. I know Perl (Perl4, not Perl5), but I really do not like it, because it has a toy language smell (it still exists). Object-oriented language seems very promising. I know Python at the time. But I do not like it, because I do not think it is a true object-oriented language - the OO feature seems to be an add on to the language. As a language maniac and OO fan for 15 years, I really want an object-oriented and easy-to-use script language. I searched but could not find it. So I decided to make it.

Matsumoto describes Ruby's design as a simple Lisp language at its core, with object systems like Smalltalk, blocks inspired by high-level functions, and practical utilities like Perl.

The name "Ruby"

The name "Ruby" originated in an online chat session between Matsumoto and Keiju Ishitsuka on February 24, 1993, before any code was written for that language. Initially two names were suggested: "Coral" and "Ruby". Matsumoto chose the latter in e-mail then to Ishitsuka. Matsumoto then noted the factor in choosing the name "Ruby" - it was the birthstone of one of his colleagues.

First publication

The first public release of Ruby 0.95 was announced on Japanese domestic newsgroups on December 21, 1995. Subsequently, three other Ruby versions were released in two days. This release coincides with the launch of the Japanese ruby-list mailing list, which is the first mailing list for the new language.

Already at this stage of development are many known features in the next Ruby release, including object-oriented design, class with inheritance, mixins, iterators, closures, exception handling and garbage collection.

Initial release

After the release of Ruby 0.95 in 1995, several stable versions of Ruby were released in the following years:

  • Ruby 1.0: December 25, 1996
  • Ruby 1.2: December 1998
  • Ruby 1.4: August 1999
  • Ruby 1.6: September 2000

In 1997, the first article on Ruby was published on the Web. In the same year, Matsumoto was hired by netlab.jp to work on Ruby as a full time developer.

In 1998, Ruby's Application Archive was launched by Matsumoto, along with a simple English homepage for Ruby.

In 1999, the first English-language mailing list ruby-talk began, signifying increased interest in languages ​​outside of Japan. In the same year, Matsumoto and Keiju Ishitsuka wrote the first book on Ruby, The Object Oriented Ruby Scripting Language (?????????????????? Ruby), published in Japan in October 1999. This will be followed in the early 2000s by about 20 books on Ruby published in Japanese.

In 2000, Ruby was more popular than Python in Japan. In September 2000, the first English text book Ruby Programming was printed, which was then freely released to the public, further expanding the use of Ruby among English speakers. In early 2002, the English-language ruby-talk mailing list received more messages than the Japanese ruby-list , showing Ruby's increasing popularity in non-Japanese languages. world.

Ruby 1.8

Ruby 1.8 was originally released in August 2003, stable for a long time, and retired in June 2013. Although it's been abandoned, there's still code based on that. Ruby 1.8 is only partially compatible with Ruby 1.9.

Ruby 1.8 has been the subject of several industry standards. The language specification for Ruby was developed by the Open Standards Promotion Center of the Information Technology Promotion Agency (Japanese government agency) to be submitted to the Japan Industry Standards Committee (JISC) and then to the International Organization for Standardization (ISO). It was accepted as Japanese Industrial Standard (JIS X 3017) in 2011 and international standard (ISO/IEC 30170) in 2012.

Around 2005, Ruby's language interest increased with Ruby on Rails, a web framework written in Ruby. The rails are often credited with Ruby's increasing awareness.

Ruby 1.9

Ruby 1.9 was released on Christmas Day in 2007. Effective with Ruby 1.9.3, released October 31, 2011, Ruby is switching from a double license under the Ruby License and the GPL becomes licensed under the Ruby License and two-license BSD clauses. The 1.9 adoption is slowed by a change from 1.8 which requires many popular third-party gems to rewrite.

Ruby 1.9 introduces many significant changes to the 1.8 series. Example:

  • blocks local variables (variables that are local to the block in which they are declared)
  • additional lambda syntax: f = - & gt; ( a , b ) { put a b }
  • Additional Hash literal syntax uses a colon for the symbol keys: { symbol_key : "value" } == { : symbol_key = & gt; "value" }
  • character encoding per string is supported
  • new socket socket (IPv6 support)
  • require_relative import security

Ruby 1.9 has been deprecated since February 23, 2015, and will no longer receive bug fixes and security. Users are encouraged to upgrade to a newer version.

Ruby 2.0

Ruby 2.0 adds several new features, including:

  • keyword method argument,
  • new method, Module # prepend , to expand the class,
  • a new literal to create a symbol array,
  • New API for lazy evaluation of Enumerables, and
  • The new convention uses #to_h to convert the object to Hash.

Ruby 2.0 is intended to be fully compatible with Ruby 1.9.3. In the official release of 2.0.0 on February 24, 2013, there are only five known (minor) incompatibilities.

It's been outdated since February 22, 2016, and will no longer receive bug fixes and security. Users are encouraged to upgrade to a newer version.

Ruby 2.1

Ruby 2.1.0 was released on Christmas Day 2013. This release includes speed updates, bug fixes and library.

Starting with 2.1.0, Ruby's version policy looks more like a semantic version. While similar, Ruby's version policy is not compatible with the semantic version:

Semantic versions also provide additional labels for pre-release and build metadata available as extensions to MAJOR.MINOR.PATCH format, not available in Ruby.

Ruby 2.1 has been deprecated since April 1, 2017, and will no longer receive bug fixes and security. Users are encouraged to upgrade to a newer version.

Ruby 2.2

Ruby 2.2.0 was released on Christmas Day 2014. This release includes speed fixes, bug fixes, and library updates and deletes some of the APIs that are no longer in use. Most notably, Ruby 2.2.0 introduces changes to memory handling - additional garbage collectors, support for garbage collection and option to compile directly against jemalloc. It also contains experimental support for using vfork (2) with system () and spawn (), and adds support for the Unicode 7.0 specification.

Deprecated or deleted features include callcc, DL libraries, Digest :: HMAC, lib/rational.rb, lib/complex.rb, GServer, Logger :: Application and various C API functions.

PowerPC64 Performance
Since version 2.2.1, Ruby MRI performance on PowerPC64 has been improved.

Ruby 2.3

Ruby 2.3.0 was released on Christmas Day 2015. Some important changes include:

  • The ability to mark all string literals as frozen by default with the result of a large performance boost in string operations.
  • A comparison of the desire to allow direct examination of key/value pairs, not just keys.
  • New secure navigation operator & amp ;. that can facilitate nil handling (eg instead of if obj & amp; obj . foo & amp; & amp; obj . foo . bar , we can use if obj & amp..foo & amp;.bar ).
  • The did_you_mean gem is now bundled by default and required on startup to automatically suggest a similar name match on NameError or NoMethodError .
  • Hash # dig and Array # dig to easily extract highly layered values ​​(for example, given profile = { social : < span> name : 'Foo Baz' } } } , the value of Foo Baz can now be retrieved by profile.dig (: social, Ã,: wikipedia, Ã,: name) ).
  • .grep_v (regexp) that will match all negative instances of certain regular expressions in addition to other new features.

Branch 2.3 also includes many performance improvements, updates and bug fixes including changes to Proc # calls, Sockets and IO usage of exception keywords, Thread # name handling, Net :: FTP default connections, and Rake deleted from stdlib.

Ruby 2.4

Ruby 2.4.0 was released on Christmas Day 2016. Some important changes include:

  • Binding # irb: Start an REPL session similar to binding.pry
  • Unify Fixnum and Bignum into the Integer class
  • String supports Unicode case mapping, not just ASCII
  • New method, Regexp # matching ?, which is boolean version faster than matching # Regular
  • The deadlock thread detection now displays the thread with backtrace and dependency

Branch 2.4 also includes performance improvements for hash tables, Array # max, Array # min, and Instant variable access.

The popularity of Ruby has declined since 2014, a slip that may be permanent in the face of increasingly fierce competition.

Ruby 2.5

Ruby 2.5.0 was released on Christmas Day in 2017. Some important changes include:

  • rescue and make sure reports automatically using the do-end block around it (less need for extras block)
  • Method-chaining with yield_self
  • Supports branch coverage and method coverage measurements
  • Hash easier transformation with Hash # slice and Hash # transformation_keys

On top of that comes a lot of performance improvements like faster passing blocks (3 times faster), faster Mutexes, faster ERB templates and fixes on some merge methods.

Maps Ruby (programming language)



List of versions


ruby programming language paper certification with laptop and real ...
src: st3.depositphotos.com


Philosophy

Matsumoto says that Ruby is designed for programmer productivity and fun, adhering to the principles of good user interface design. At Google Tech Talk in 2008 Matsumoto went on to state, "I hope Ruby can help every programmer in the world to be productive, and enjoy programming, and be happy.That's the main goal of Ruby." He emphasized that the design of the system needs to emphasize the human need, not the computer,

Often people, especially computer engineers, focus on machines. They think, "By doing this, the machine will run fast, by doing this, the machine will run more effectively by doing this, the machine will do something." They focus on the machine. But actually we need to focus on humans, on how humans care about doing programming or operating machine applications. We are masters. They are slaves.

Ruby is said to follow the principle of least astonishment (POLA), which means that language must behave in such a way as to minimize confusion for experienced users. Matsumoto says his main design goal is to create a language he himself likes to use, by minimizing the work of the programmer and possible confusion. He has said that he did not apply the most surprising principle to Ruby's design, but nevertheless the phrase has been closely linked to the Ruby programming language. The phrase itself has been a source of surprise, because novice users can think of it as a Ruby behavior that tries to adjust behavior that is familiar with other languages. In a May 2005 discussion at comp.lang.ruby newsgroup, Matsumoto tried to keep Ruby out of POLA, explaining that since any design choice would surprise someone, he used personal standards in evaluating surprises. If the personal standards remain consistent, there will be some surprises for those familiar with the standards.

Matsumoto defines it this way in an interview:

Everyone has an individual background. Someone may come from Python, others may come from Perl, and they may be surprised by various aspects of the language. Then they came up to me and said, 'I'm shocked by this language feature, so Ruby violates the least shocking principle.' Wait. Wait. The least shocking principle is not just for you. The least surprising principle is the principle of the most shock I . And that means the least shocking principle once you learn Ruby very well. For example, I was a C programmer before I started designing Ruby. I program in C exclusively for two or three years. And after two years of C programming, it still surprises me.


heart ruby tattoo | Ruby ・ Ruby (programming language) | Hearts ...
src: i.pinimg.com

Features

  • Completely object-oriented with inheritance, mixin, and metaclasses
  • Typing dynamic and typing duck
  • Everything is an expression (even statement) and everything is executed imperatively (even declarations)
  • A short, flexible syntax that minimizes syntactic noise and serves as a foundation for domain-specific languages ​​
  • Dynamic reflection and object changes to facilitate metaprogramming
  • Lexis closure, iterator, and generator, with block syntax
  • A literal notation for arrays, hashes, regular expressions, and symbols
  • Embed the code in the string (interpolation)
  • Default argument
  • The four levels of the scope of the variables (global, class, instance, and local) are denoted by sigils or absence
  • Garbage collection
  • First class continuation
  • Strict boolean enforcement rules (all true except false and nil )
  • Exception handling
  • Operator overloading
  • Internal support for rational numbers, complex numbers, and random-precision arithmetic
  • Custom delivery behavior (via method_missing and const_missing )
  • Original yarn and co-operative fiber (fiber is 1.9/YARV feature)
  • Initial support for Unicode and multiple character encodings (without ICU support)
  • native plug-in API in C
  • Interactive Ruby Shell (REPL)
  • Package management is centralized via RubyGems
  • Implemented on all major platforms
  • Large standard libraries, including modules for YAML, JSON, XML, CGI, OpenSSL, HTTP, FTP, RSS, curses, zlib, and Tk

Ruby - Programming Language Logo
src: ih0.redbubble.net


Semantics

Ruby object-oriented: each value is an object, including classes and instances of a type in which many other languages ​​are defined as primitives (such as integers, booleans, and "null"). The variable always holds a reference to the object. Each function is a method and a method always called on an object. The method defined at the top level becomes the Object class method. Since this class is the ancestor of every other class, such methods can be called on any object. They are also visible in all spheres, effectively functioning as a "global" procedure. Ruby supports inheritance by the dynamic dispatch, mixins, and singleton methods (property, and is defined for, one instance rather than defined in the class). Although Ruby does not support multiple inheritance, classes can import modules as mixins.

Ruby has been described as a multi-paradigm programming language: it allows procedural programming (defining functions/variables outside the class makes them part of the root, 'self' Object), with object orientation (everything is an object) or functional programming (it has an anonymous function , closing, and continuation, all statements have value, and function returns the last evaluation). It has support for introspection, reflection and metaprogramming, as well as support for thread-based interpreters. Ruby has dynamic typing features, and supports parametric polymorphism.

According to Ruby FAQ, the syntax is similar to Perl and its semantic is similar to Smalltalk but very different from Python.

Ruby Programming Language Paper Certification With Laptop And Real ...
src: thumbs.dreamstime.com


Syntax

Ruby syntax is generally similar to Perl and Python. Class definitions and methods are tagged by keywords, while code blocks can be defined by keywords or brackets. Unlike Perl, the variable is not mandatory starting with sigil. When used, sigil alters the semantics of the variable scope. For practical purposes there is no difference between expressions and statements. The line breaks are significant and are taken as the end of a statement; semicolons can be used in an equivalent manner. Unlike Python, indentation is not significant.

One of Ruby's differences compared to Python and Perl is that Ruby keeps all its private variables entirely private to the class and only exposes them through the accessory method ( attr_writer , attr_reader , etc.). Unlike "take" and "setter" methods from other languages ​​such as C or Java, the accessor method in Ruby can be created with a single line of code through metaprogramming; However, the accessor method can also be created in traditional C and Java ways. As the prayer of this method does not require the use of parentheses, it is trivial to convert instance variables into full functionality, without modifying a single line of code calls or having to perform a similar function refactoring for C # and VB.NET member properties.

Python property descriptions are similar, but come with a tradeoff in the development process. If someone starts with Python by using an open instance variable, and then alters the implementation to use an open instance variable through the property descriptor, the internal code into the class may need to be adjusted to use private variables rather than public properties. Ruby's design forces all the instant variables to be private, but also provides a simple way to declare the set and get methods. This corresponds to the idea that in Ruby, a person never directly accesses internal members of a class from outside the classroom; instead, someone passes a message to the class and receives an answer.

See the Sample section below for a sample code that shows Ruby syntax.

Ruby Programming - 1 - Install Ruby and Editor - YouTube
src: i.ytimg.com


Interactions

Ruby's official distribution also includes irb , an interactive command line interpreter that can be used to test code quickly. The following code fragment represents the sample session using irb :

Ruby Programming Language Funny Character. Stock Vector ...
src: thumbs.dreamstime.com


Example

The following examples can be run in a Ruby shell like Interactive Ruby Shell, or stored in a file and run from the command line by typing ruby ​​â € <â € << i> & lt; filename & gt; .

Examples of classic Hello world:

Some basic Ruby code:

Enter:

Konversi:

String

There are various ways to define strings in Ruby.

The following tasks are equivalent:

Strings supports variable interpolation:

The following tasks are equivalent and generate a raw string:

Collection

Build and use array:

Build and use associative arrays (in Ruby, called hash ):

Control structure

Jika pernyataan:

Blok dan iterator

Two syntax for creating code blocks:

The code block can be passed to the method as an optional block argument. Many default methods have such arguments:

Parameter-passes block to be closing:

Create an anonymous function:

Returns the closure of the method:

Generate program control flow to block provided at call time:

Iterating over enumeration and arrays using blocks:

Methods like inject can accept parameters and blocks. The inject method repeats each list member, performing some functionality on it while maintaining aggregate. This is analogous to the foldl function in functional programming languages. As an example:

At first pass, the block receives 10 (arguments to insert) as sum , and 1 (the first element of the array) as element . This returns 11, which then becomes amount on the next path. It was added to 3 to get 14, which was then added to 5 at the third pass, to finally restore 19.

Use enumeration and block to create squares of 1 to 10 (using range ):

Or use the method on each item ( map is a synonym for collect ):

Class

The following code defines a class named Person . In addition to initialize , the ordinary constructor for creating a new object, it has two methods: one to change the comparison operator & lt; = & gt; (so Array # sorting can sort by age) and others to change the to_s method (so Kernel # puts can format the output ). Here, attr_reader is an example of metaprogramming in Ruby: attr_accessor defines the getter and setter methods of an instance variable, but attr_reader is just a getter method. The last statement evaluated in a method is the return value, allowing the removal of an explicit statement return .

The previous code prints three names in reverse age order:

Person is a constant and is a reference to the Class object.

Open class

In Ruby, classes are never closed: methods can always be added to an existing class. This applies to all classes, including existing standard classes. All that needs to be done is to open the class definition for an existing class, and the new content specified will be added to the existing content. A simple example adds a new method to the standard Time library class:

Adding a method to a previously defined class is often called a monkey patch. If done haphazardly, the practice may lead to a behavioral collision with subsequent unexpected results and code scalability issues.

Since Ruby 2.0, it is possible to use fixes to reduce the negative consequences of patching monkeys, by limiting the scope of patches to specific areas of the codebase.

Exceptions

Exceptions raised with the call raise :

Optional messages can be added to exceptions:

Exceptions can also be determined by the programmer:

Alternatively, an exception instance can be passed to the raise method:

This last construct is useful when upgrading instances of special exception classes that display constructors that take more than one argument:

Exceptions are handled by the rescue clause. Such clauses can capture exceptions that inherit from StandardError . Other flow control keywords that can be used when handling exceptions are else and make sure :

It is a common mistake to try to catch all exceptions with a simple rescue clause. To capture all exceptions, one must write:

Or capture certain exceptions:

It is also possible to specify that the exception object is provided for the handler clause:

Alternatively, the latest exceptions are stored in a global miracle $! .

Some exceptions may also be caught:

Metaprogramming

Ruby codes can be programmed to modify, at runtime, aspects of their own structures that will be fixed in more rigid languages, such as class definitions and methods. This kind of metaprogramming can be used to write more concise code and effectively extend the language.

For example, the following Ruby code generates a new method for the default String class, based on the color list. Method wrap the contents of the string with HTML tags are arranged with their respective colors.

The resulting method can then be used like this:

To apply equivalents in many other languages, the programmer must write each method ( in_black , in_red , in_green , etc.) separately.

Some other possible uses for Ruby's metaprogramming include:

  • intercepts and modifies method calls
  • apply the new inheritance model
  • dynamically generates a class from the
  • parameter
  • automatic object serialization
  • interactive help and debugging

More examples

More Ruby code examples are available as algorithms in the following article:

  • Expand by squaring

Introduction to the Ruby Programming Language - YouTube
src: i.ytimg.com


Implementations

Translator Ruby Matz

The original Ruby interpreter is often referred to as Ruby Interpreter or MRI Matz. This implementation is written in C and uses a special Ruby own virtual machine.

The implementation of Ruby 1.8 standards and pensions is written in C, as a single interpreted language.

Starting with Ruby 1.9, and followed by Ruby 2.x and later, the official Ruby interpreter has YARV ("Yet Another Ruby VM"), and this implementation has replaced the slower virtual machine used on previous MRI releases.

Alternative implementations

By 2018, there are a number of alternative implementations of Ruby, including JRuby, Rubinius, and mruby. Each takes a different approach, with JRuby and Rubinius providing timely compilations and mruby also providing compilations ahead of time.

Ruby has three main alternative implementations:

  • JRuby, a Java implementation that runs on a Java virtual machine. JRuby is currently targeting Ruby 2.3.
  • TruffleRuby, a Java implementation using the Truffle language implementation framework with GraalVM
  • Rubinius, a virtual C bytecode engine that uses LLVM to compile machine code at runtime. The bytecode compiler and most of the core classes are written in pure Ruby. Rubinius is currently targeting Ruby 2.1,

Other Ruby implementations include:

  • MagLev, Smalltalk implementation running on GemStone/S VM GemTalk Systems
  • mruby, an implementation designed to be embedded into C code, in a tone similar to Lua. Currently being developed by Yukihiro Matsumoto and others
  • RGSS, or Ruby Game Scripting System, an exclusive implementation used by RPG Maker software for game design and RPG Maker machine modifications
  • A transpiler (partly) from Ruby to Julia, julializer available. This can be used for large accelerations rather than for example Ruby or JRuby Implementation (may be useful only for numerical codes).
  • Topaz, the Ruby implementation is written in Python
  • Opal, a web-based interpreter that Ruby compiles into JavaScript

Other Ruby Implementations that are no longer working are:

  • MacRuby, a Mac OS X implementation in the Objective-C runtime. Its iOS partners are called RubyMotion
  • IronRuby an implementation on the.NET Framework
  • Cardinal, implementation for Parrot virtual machine
  • Ruby Enterprise Edition, often abbreviated as ree , an implementation that is optimized to handle large-scale Ruby on Rails projects
  • HotRuby, JavaScript and ActionScript implementations of the Ruby programming language

The maturity of Ruby's implementation tends to be measured by their ability to run Ruby on Rails (Rails) framework, as it is very complex to implement and use many of Ruby's specific features. The point when a particular implementation reaches this goal is called "Rails singularity". Reference implementations (MRI), JRuby, and Rubinius are all capable of running unmodified Rails in the production environment.

Platform support

Matsumoto originally developed Ruby on Sony OS-based OSS 4.3S based OS 3.x, but later migrated his work to SunOS 4.x, and finally to Linux.

In 1999, Ruby was known to work on many different operating systems, including NEWS-OS, SunOS, AIX, SVR4, Solaris, NEC UP-UX, NeXTSTEP, BSD, Linux, Mac OS, DOS, Windows and BeOS.

Modern Ruby versions and applications are available on many operating systems, such as Linux, BSD, Solaris, AIX, macOS, Windows, Windows Phone, Windows CE, Symbian OS, BeOS and IBM i.

Ruby - Programming Language Logo
src: ih0.redbubble.net


Repository and library

RubyGems is Ruby package manager. The Ruby package is called "gem" and can be easily installed via the command line. Most gems are libraries, though there are some that are apps, such as IDE. There are over 9,000 Ruby gems hosted at RubyGems.org.

Many new and existing Ruby libraries are hosted on GitHub, a service that offers hosting version control repositories for Git.

The Ruby Application Archive, which houses Ruby's application, documentation and libraries for programming, is retained until 2013, when its functionality is moved to RubyGems.


See also

  • Comparison of programming languages ​​
  • Metasploit Project - the world's largest Ruby project, with over 700,000 lines of code
  • Why a (sharp) Guide to Ruby - an online ruby ​​book in a graphic novel format
  • XRuby



References




Further reading




External links

  • Official website
  • Official Ruby Documentation
  • Ruby User's Guide - by Yukihiro Matsumoto, the creator of Ruby
  • Community-driven coding style guides
  • Ruby From Other Languages ​​
  • Ruby Forum - gateway to the ruby-talk mailing list
  • Try Ruby! Ã, - Ruby REPL web-based
  • Ruby Draft Specification, September 2010
  • Ruby on Curlie (based on DMOZ)

Source of the article : Wikipedia

Comments
0 Comments