ruby2.6.2

官方:https://www.ruby-lang.org/en/

一 简介

A dynamic, open source programming language with a focus on simplicity and productivity. It has an elegant syntax that is natural to read and easy to write.

Ruby is a language of careful balance. Its creator, Yukihiro “Matz” Matsumoto, blended parts of his favorite languages (Perl, Smalltalk, Eiffel, Ada, and Lisp) to form a new language that balanced functional programming with imperative programming.

Since its public release in 1995, Ruby has drawn devoted coders worldwide. In 2006, Ruby achieved mass acceptance. With active user groups formed in the world’s major cities and Ruby-related conferences filled to capacity.

ruby首次发布于1995年;在2006年,ruby开始被广泛接受;

Ruby is ranked among the top 10 on most of the indices that measure the growth and popularity of programming languages worldwide (such as the TIOBE index). Much of the growth is attributed to the popularity of software written in Ruby, particularly the Ruby on Rails web framework.

ruby一直位于编程语言top10,很多增长来自于使用ruby编写的软件,比如ruby on rails;

Initially, Matz looked at other languages to find an ideal syntax. Recalling his search, he said, “I wanted a scripting language that was more powerful than Perl, and more object-oriented than Python.”

Ruby is seen as a flexible language, since it allows its users to freely alter its parts. Essential parts of Ruby can be removed or redefined, at will. Existing parts can be added upon. Ruby tries not to restrict the coder.

Ruby, as a language, has a few different implementations. This page has been discussing the reference implementation, in the community often referred to as MRI (“Matz’s Ruby Interpreter”) or CRuby (since it is written in C), but there are also others. They are often useful in certain situations, provide extra integration to other languages or environments, or have special features that MRI doesn’t.

ruby作为一种语言,有很多种不同的实现,比如cruby,jruby;

JRuby is Ruby atop the JVM (Java Virtual Machine), utilizing the JVM’s optimizing JIT compilers, garbage collectors, concurrent threads, tool ecosystem, and vast collection of libraries.

jruby是jvm上的ruby;

二 安装

1 使用网页版

https://ruby.github.io/TryRuby/

2 使用docker

$ docker run -it --rm --name my-running-script -v "$PWD":/usr/src/myapp -w /usr/src/myapp ruby:2.6.2 ruby your-daemon-or-script.rb

参考:https://hub.docker.com/_/ruby/

3 使用rbenv

  1. # 1 install rbenv
    $ git clone https://github.com/rbenv/rbenv.git ~/.rbenv
  2. $ cd ~/.rbenv && src/configure && make -C src
  3. $ echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bash_profile
  4. $ source ~/.bash_profile
  5. $ ~/.rbenv/bin/rbenv init

  6. # 2 install ruby-build plugin
  7. $ mkdir -p "$(rbenv root)"/plugins
  8. $ git clone https://github.com/rbenv/ruby-build.git "$(rbenv root)"/plugins/ruby-build

  9. # 3 install ruby
  10. $ rbenv install -l
  11. $ rbenv install 2.6.2
  12.  
  13. # 4 use ruby
    $ rbenv shell 2.6.2
    $ ruby -v
    ruby 2.6.2p47 (2019-03-13 revision 67232) [x86_64-linux]
    $ ruby test.rb

安装时可能报错:

$ rbenv install 2.6.2

Downloading ruby-2.6.2.tar.bz2...
-> https://cache.ruby-lang.org/pub/ruby/2.6/ruby-2.6.2.tar.bz2
Installing ruby-2.6.2...

BUILD FAILED (CentOS 7.4.1708 using ruby-build 20190314-4-g8e70553)

Inspect or clean up the working tree at /tmp/ruby-build.20190319152414.23377
Results logged to /tmp/ruby-build.20190319152414.23377.log

Last 10 log lines:
installing html-docs: /root/.rbenv/versions/2.6.2/share/doc/ruby
installing capi-docs: /root/.rbenv/versions/2.6.2/share/doc/ruby
The Ruby readline extension was not compiled.
ERROR: Ruby install aborted due to missing extensions
Try running `yum install -y readline-devel` to fetch missing dependencies.

按照提示安装即可

yum install -y readline-devel

参考
https://github.com/rbenv/rbenv
https://github.com/rbenv/ruby-build

三 使用

  1. $ cat /tmp/test.rb
  2. puts 'hello world'
  3. $ ruby /tmp/test.rb
  4. hello world

ruby有很多应用,比如logstash、ruby on rails等;

ruby api 参考:https://ruby-doc.org/core-2.6.2/

【原创】编程基础之Ruby的更多相关文章

  1. (转)Windows驱动编程基础教程

    版权声明     本书是免费电子书. 作者保留一切权利.但在保证本书完整性(包括版权声明.前言.正文内容.后记.以及作者的信息),并不增删.改变其中任何文字内容的前提下,欢迎任何读者 以任何形式(包括 ...

  2. 【转】Shell编程基础篇-上

    [转]Shell编程基础篇-上 1.1 前言 1.1.1 为什么学Shell Shell脚本语言是实现Linux/UNIX系统管理及自动化运维所必备的重要工具, Linux/UNIX系统的底层及基础应 ...

  3. 【Shell 编程基础第二部分】Shell里的流程控制、Shell里的函数及脚本调试方法!

    http://blog.csdn.net/xiaominghimi/article/details/7603003 本站文章均为李华明Himi原创,转载务必在明显处注明:转载自[黑米GameDev街区 ...

  4. Linux学习之二十一-shell编程基础

    Shell编程基础 Shell 是一个用 C 语言编写的程序,它是用户使用 Linux 的桥梁.Shell 既是一种命令语言,又是一种程序设计语言.Shell 是指一种应用程序,这个应用程序提供了一个 ...

  5. Java并发编程系列-(1) 并发编程基础

    1.并发编程基础 1.1 基本概念 CPU核心与线程数关系 Java中通过多线程的手段来实现并发,对于单处理器机器上来讲,宏观上的多线程并行执行是通过CPU的调度来实现的,微观上CPU在某个时刻只会运 ...

  6. SHELL脚本编程基础知识

    SHELL脚本编程基础知识 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. Linux之父Linus有一句话很经典:"Talk is cheap, show me the ...

  7. 【转】以Python为例的Async / Await的编程基础

    转, 原文:https://www.cnblogs.com/middleware/p/11996731.html 以Python为例的Async / Await的编程基础 -------------- ...

  8. 第二章 Matlab面向对象编程基础

    DeepLab是一款基于Matlab面向对象编程的深度学习工具箱,所以了解Matlab面向对象编程的特点是必要的.笔者在做Matlab面向对象编程的时候发现无论是互联网上还是书店里卖的各式Matlab ...

  9. [.net 面向对象编程基础] (1) 开篇

    [.net 面向对象编程基础] (1)开篇 使用.net进行面向对象编程也有好长一段时间了,整天都忙于赶项目,完成项目任务之中.最近偶有闲暇,看了项目组中的同学写的代码,感慨颇深.感觉除了定义个类,就 ...

随机推荐

  1. SQL Server进阶(七)集合运算

    概述 为什么使用集合运算: 在集合运算中比联接查询和EXISTS/NOT EXISTS更方便. 并集运算(UNION) 并集:两个集合的并集是一个包含集合A和B中所有元素的集合. 在T-SQL中.UN ...

  2. 【python小练】0001

    第 0001 题:做为 Apple Store App 独立开发者,你要搞限时促销,为你的应用生成激活码(或者优惠券),使用 Python 如何生成 200 个激活码(或者优惠券)? # coding ...

  3. 剑指offer: 数组中的逆序对

    1. 最简单的思路,对每个值,遍历与其逆序的数组对:但时间复杂度太高: 2. 归并排序的思路: 先将数组分隔成子数组,先统计出子数组内的逆序对的数目,然后统计两个相邻子数组之间的逆序对的数目: int ...

  4. dll和lib的关系(转)

    转自http://blog.163.com/zhengjiu_520/blog/static/3559830620093583438464/ 前面有一章说编译与链接的,说得很简略,其实应该放到这一章一 ...

  5. 前段js的各种弹出框

    artDialog 首页 > 文档与示例 artDialog —— 经典的网页对话框组件,内外皆用心雕琢. 支持普通与 12 方向气泡状对话框 完善的焦点处理,自动焦点附加与回退 支持 ARIA ...

  6. JS中原型链中的prototype与_proto_的个人理解与详细总结

    1.对象的内部属性[[prototype]]和属性__proto__:每个对象都具有一个名为__proto__的属性: 2.函数的属性prototype:每个构造函数(构造函数标准为大写开头,如Fun ...

  7. Shiro入门 - 通过ini文件进行授权

    shiro-permission.ini #用户 [users] #admin的密码是111111,此用户具有role1.role2两个角色 admin=111111,role1,role2 zhan ...

  8. ==,hashcde, equals(一)

    1.Hash  的属性, 1)bucket 和 list 2.java.lang.object 的 hashcode 和 equal 通过内存地址比较 3.为什么要重写hashcode 和 equal ...

  9. #6279. 数列分块入门 3(询问区间内小于某个值 xx 的前驱(比其小的最大元素))

    题目链接:https://loj.ac/problem/6279 题目大意:中文题目 具体思路:按照上一个题的模板改就行了,但是注意在整块查找的时候的下标问题. AC代码: #include<b ...

  10. nginx 开启静态 gzip 配合 Vue 构建

    在站点配置添加如下代码: location ~* \.(css|js)$ { gzip_static on; } 这是 nginx 的静态 gzip功能,会自动查找对应扩展名的文件,如果存在 gzip ...