Ruby 类的创建
class Language
def initialize(name, creator)
@name = name
@creator = creator
end
def description
puts "I'm #{@name} and I was created by #{@creator}!"
end
end
ruby = Language.new("Ruby", "Yukihiro Matsumoto")
python = Language.new("Python", "Guido van Rossum")
javascript = Language.new("JavaScript", "Brendan Eich")
ruby.description
python.description
javascript.description
- 类名首字母大写,NewClass (方法名首字母小写,多个单词用下划线连接)
- 初始化函数 initialize, 参数为name, creator
- 实例变量赋值@name = name (python self.name = name)
- 创建实例 ruby = Language.new("Ruby", "Yukihiro Matsumoto")
- 调用类函数 ruby.description
- @关键字 + 变量名 表示该变量为实例变量
Ruby 类的创建的更多相关文章
- Ruby类的创建与使用
Ruby是一种面向对象编程语言,这意味着它操纵的编程结构称为"对象" 先上代码, 了解类的定义与使用方式 class Computer $manufacturer = " ...
- Ruby类
Ruby类 类定义 #!/usr/bin/ruby class Sample def hello puts "Hello Ruby!" end end # 使用上面的类来创建对象 ...
- 雷林鹏分享:Ruby 类和对象
Ruby 类和对象 Ruby 是一种完美的面向对象编程语言.面向对象编程语言的特性包括: 数据封装 数据抽象 多态性 继承 这些特性将在 面向对象的 Ruby 中进行讨论. 一个面向对象的程序,涉及到 ...
- 雷林鹏分享:Ruby 类案例
Ruby 类案例 下面将创建一个名为 Customer 的 Ruby 类,您将声明两个方法: display_details:该方法用于显示客户的详细信息. total_no_of_customers ...
- Ruby 类和对象
Ruby 类和对象 Ruby 是一种完美的面向对象编程语言.面向对象编程语言的特性包括: 数据封装 数据抽象 多态性 继承 这些特性将在 面向对象的 Ruby 中进行讨论. 一个面向对象的程序,涉及到 ...
- C# 根据类名称创建类示例
//获得类所在的程序集名称(此处我选择当前程序集) string bllName = System.IO.Path.GetFileNameWithoutExtension(System.Reflect ...
- php简单实用的操作文件工具类(创建、移动、复制、删除)
php简单实用好用的文件及文件夹复制函数和工具类(创建.移动.复制.删除) function recurse_copy($src,$dst) { // 原目录,复制到的目录 $dir = opend ...
- 李洪强iOS开发之OC[013] -类的创建的练习
// // main.m // 12 - 类的创建练习 // // Created by vic fan on 16/7/9. // Copyright © 2016年 李洪强. All ri ...
- C++:类的创建
类的创建 #include<iostream> #include<cmath> using namespace std; class Complex //声明一个名为Compl ...
随机推荐
- widows 2008 同步时间命令
由于windows2008没有提供类似XP的自动同步功能,因此需要使用windows 2008计划任务来运行一行命令进行同步. 首先查看与想要同步时间的internet时间服务器的时差: w32t ...
- python各种类型转换
python各种类型转换 学习了:https://blog.csdn.net/shanliangliuxing/article/details/7920400 https://blog.csdn.ne ...
- [Testing] Config jest to test Javascript Application -- Part 1
Transpile Modules with Babel in Jest Tests Jest automatically loads and applies our babel configurat ...
- Gas Station,转化为求最大序列的解法,和更简单简单的Jump解法。——贪心、转化
Gas Station There are N gas stations along a circular route, where the amount of gas at station i is ...
- chrome.declarativeWebRequest
chrome.declarativeWebRequest 清单文件 规则 条件与操作的求值 使用优先级覆盖规则 类型 HeaderFilter RequestMatcher CancelRequest ...
- scala快速学习笔记(二):控制结构,类和对象
IV.控制结构 1.if/else 除基本用法外,if/else语句能用来赋值,进而代替?:运算符.这得益于在Scala中,每个语句块都有值,就是该语句块最后一个语句的值.请看下面的代码. def a ...
- MVC程序部署后页面指向login.aspx
MVC程序在本地没有问题,但是部署到服务器后老是跳转到Login.aspx页面,但是我的MVC程序中根本没有Login页面,看了一下链接是这样的 htttp://localhost:26290/log ...
- 自定义UISearchDisplayController的“No Results“标签和”Cancel“按钮
本文转载至 http://www.cnblogs.com/pengyingh/articles/2350154.html - (void)searchDisplayControllerWillBegi ...
- SHOW PROCESSLIST Syntax
https://dev.mysql.com/doc/refman/5.7/en/show-processlist.html SHOW PROCESSLIST shows you which threa ...
- C标准库中atoi的一种可能的实现
为避免与标准库中的atoi产生歧义, 我将自己编写的函数命名为strToInt, 以下是示例代码 #include <stdio.h> int strToInt(const char *s ...