jagram 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 4215486de61e16d320d331c0a96516b279026d90895a6500b8ef93b3d01e7939
4
+ data.tar.gz: 53ee52ded3756319c9dad7d3538693356806b36d2526c9aa94cf28fae8bda858
5
+ SHA512:
6
+ metadata.gz: c992ae2ceb6ad2433ae9586d0c62fcd6c06119426016e0f28deff103f76c7120a46474dca4f89d33cda87cf79baa8aa696953487c1e61ea687904001aaadace4
7
+ data.tar.gz: 79a28434d9effbbd25b3cc67154e35afc5cc4258cd7601bb9f8d0d3a1c71da4b0d89f72c498a48575c32ae36ada8f362f40a461a06926b4db1f10ca8e65e0e79
@@ -0,0 +1,16 @@
1
+ name: Ruby
2
+
3
+ on: [push,pull_request]
4
+
5
+ jobs:
6
+ build:
7
+ runs-on: ubuntu-latest
8
+ steps:
9
+ - uses: actions/checkout@v2
10
+ - name: Set up Ruby
11
+ uses: ruby/setup-ruby@v1
12
+ with:
13
+ ruby-version: 2.7.2
14
+ bundler-cache: true
15
+ - name: Run the default task
16
+ run: bundle exec rake
data/.gitignore ADDED
@@ -0,0 +1,11 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ # rspec failure tracking
11
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/CHANGELOG.md ADDED
@@ -0,0 +1,5 @@
1
+ ## [Unreleased]
2
+
3
+ ## [0.1.0] - 2021-11-21
4
+
5
+ - Initial release
@@ -0,0 +1,84 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ We as members, contributors, and leaders pledge to make participation in our community a harassment-free experience for everyone, regardless of age, body size, visible or invisible disability, ethnicity, sex characteristics, gender identity and expression, level of experience, education, socio-economic status, nationality, personal appearance, race, religion, or sexual identity and orientation.
6
+
7
+ We pledge to act and interact in ways that contribute to an open, welcoming, diverse, inclusive, and healthy community.
8
+
9
+ ## Our Standards
10
+
11
+ Examples of behavior that contributes to a positive environment for our community include:
12
+
13
+ * Demonstrating empathy and kindness toward other people
14
+ * Being respectful of differing opinions, viewpoints, and experiences
15
+ * Giving and gracefully accepting constructive feedback
16
+ * Accepting responsibility and apologizing to those affected by our mistakes, and learning from the experience
17
+ * Focusing on what is best not just for us as individuals, but for the overall community
18
+
19
+ Examples of unacceptable behavior include:
20
+
21
+ * The use of sexualized language or imagery, and sexual attention or
22
+ advances of any kind
23
+ * Trolling, insulting or derogatory comments, and personal or political attacks
24
+ * Public or private harassment
25
+ * Publishing others' private information, such as a physical or email
26
+ address, without their explicit permission
27
+ * Other conduct which could reasonably be considered inappropriate in a
28
+ professional setting
29
+
30
+ ## Enforcement Responsibilities
31
+
32
+ Community leaders are responsible for clarifying and enforcing our standards of acceptable behavior and will take appropriate and fair corrective action in response to any behavior that they deem inappropriate, threatening, offensive, or harmful.
33
+
34
+ Community leaders have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, and will communicate reasons for moderation decisions when appropriate.
35
+
36
+ ## Scope
37
+
38
+ This Code of Conduct applies within all community spaces, and also applies when an individual is officially representing the community in public spaces. Examples of representing our community include using an official e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event.
39
+
40
+ ## Enforcement
41
+
42
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported to the community leaders responsible for enforcement at t.yasukawa01@gmail.com. All complaints will be reviewed and investigated promptly and fairly.
43
+
44
+ All community leaders are obligated to respect the privacy and security of the reporter of any incident.
45
+
46
+ ## Enforcement Guidelines
47
+
48
+ Community leaders will follow these Community Impact Guidelines in determining the consequences for any action they deem in violation of this Code of Conduct:
49
+
50
+ ### 1. Correction
51
+
52
+ **Community Impact**: Use of inappropriate language or other behavior deemed unprofessional or unwelcome in the community.
53
+
54
+ **Consequence**: A private, written warning from community leaders, providing clarity around the nature of the violation and an explanation of why the behavior was inappropriate. A public apology may be requested.
55
+
56
+ ### 2. Warning
57
+
58
+ **Community Impact**: A violation through a single incident or series of actions.
59
+
60
+ **Consequence**: A warning with consequences for continued behavior. No interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, for a specified period of time. This includes avoiding interactions in community spaces as well as external channels like social media. Violating these terms may lead to a temporary or permanent ban.
61
+
62
+ ### 3. Temporary Ban
63
+
64
+ **Community Impact**: A serious violation of community standards, including sustained inappropriate behavior.
65
+
66
+ **Consequence**: A temporary ban from any sort of interaction or public communication with the community for a specified period of time. No public or private interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, is allowed during this period. Violating these terms may lead to a permanent ban.
67
+
68
+ ### 4. Permanent Ban
69
+
70
+ **Community Impact**: Demonstrating a pattern of violation of community standards, including sustained inappropriate behavior, harassment of an individual, or aggression toward or disparagement of classes of individuals.
71
+
72
+ **Consequence**: A permanent ban from any sort of public interaction within the community.
73
+
74
+ ## Attribution
75
+
76
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 2.0,
77
+ available at https://www.contributor-covenant.org/version/2/0/code_of_conduct.html.
78
+
79
+ Community Impact Guidelines were inspired by [Mozilla's code of conduct enforcement ladder](https://github.com/mozilla/diversity).
80
+
81
+ [homepage]: https://www.contributor-covenant.org
82
+
83
+ For answers to common questions about this code of conduct, see the FAQ at
84
+ https://www.contributor-covenant.org/faq. Translations are available at https://www.contributor-covenant.org/translations.
data/Gemfile ADDED
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org"
4
+
5
+ # Specify your gem's dependencies in jagram.gemspec
6
+ gemspec
7
+
8
+ gem "rake", "~> 13.0"
9
+
10
+ group :development do
11
+ gem 'yard'
12
+ end
13
+
14
+ group :test, :development do
15
+ gem 'pry', '~> 0.13.1'
16
+ gem "rspec", "~> 3.0"
17
+ end
data/Gemfile.lock ADDED
@@ -0,0 +1,42 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ jagram (0.1.0)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ coderay (1.1.3)
10
+ diff-lcs (1.4.4)
11
+ method_source (1.0.0)
12
+ pry (0.13.1)
13
+ coderay (~> 1.1)
14
+ method_source (~> 1.0)
15
+ rake (13.0.6)
16
+ rspec (3.10.0)
17
+ rspec-core (~> 3.10.0)
18
+ rspec-expectations (~> 3.10.0)
19
+ rspec-mocks (~> 3.10.0)
20
+ rspec-core (3.10.1)
21
+ rspec-support (~> 3.10.0)
22
+ rspec-expectations (3.10.1)
23
+ diff-lcs (>= 1.2.0, < 2.0)
24
+ rspec-support (~> 3.10.0)
25
+ rspec-mocks (3.10.2)
26
+ diff-lcs (>= 1.2.0, < 2.0)
27
+ rspec-support (~> 3.10.0)
28
+ rspec-support (3.10.3)
29
+ yard (0.9.26)
30
+
31
+ PLATFORMS
32
+ x86_64-darwin-20
33
+
34
+ DEPENDENCIES
35
+ jagram!
36
+ pry (~> 0.13.1)
37
+ rake (~> 13.0)
38
+ rspec (~> 3.0)
39
+ yard
40
+
41
+ BUNDLED WITH
42
+ 2.2.17
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2021 samurait
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,215 @@
1
+ # Jagram
2
+
3
+ jagram(ジャグラム)とは、JApanese proGRAMming Languageの略で、
4
+ 日本語でかけるプログラミング言語を目指して作ったものです。
5
+ 日本におけるプログラミングの教育の場などで、使われたらと思い作成しました。
6
+
7
+ また、rubyのDSLを使って作成しているため、既存のrubyコードと共存できたり、
8
+ jagramでロジックがわかるようになったら、rubyに移行するのような使い方ができます。
9
+
10
+ ## Installation
11
+
12
+ Gemファイルを使っている場合は、gemにjagramを指定
13
+
14
+ ```ruby
15
+ gem 'jagram'
16
+ ```
17
+
18
+ そして、次を実行
19
+
20
+ $ bundle install
21
+
22
+ あるいは、直接jagramをインストール
23
+
24
+ $ gem install jagram
25
+
26
+
27
+ ## 使い方・構文
28
+
29
+ `require 'jagram'`でjagramが使えるようになります。
30
+
31
+ ### 繰り返し構文
32
+ #### 〜の間 構文 - whileに相当
33
+ ```ruby
34
+ require 'jagram'
35
+
36
+ i = 0
37
+ 次の条件が成り立つ間( -> { i <= 5} ) do
38
+ 次を表示する(i) #> 0,1,2,3,4,5
39
+ i += 1
40
+ end
41
+
42
+ i = 0
43
+ 結果 = ""
44
+ 次の条件が成り立つ間(-> {i <= 5}) {
45
+ 結果 += i.を文字に変換
46
+ i += 1
47
+ }
48
+ 次を表示する(結果) #> 012345
49
+ ```
50
+ #### 単純な繰り返し構文 - loopに相当
51
+ ```ruby
52
+ require 'jagram'
53
+ i = 0
54
+ 次を繰り返す {
55
+ もし(i.は, 0, ならば) do
56
+ 繰り返しから抜ける
57
+ end
58
+ 次を表示する(i) #> 0,1,2,3,4,5
59
+ i += 1
60
+ }
61
+
62
+ i = 0
63
+ 次を繰り返す do
64
+ もし(i.は, 0, ならば) do
65
+ 繰り返しから抜ける
66
+ end
67
+ 次を表示する(i) #> 0,1,2,3,4,5
68
+ i += 1
69
+ end
70
+ ```
71
+
72
+ #### 〜から〜まで繰り返す構文 - for文に相当
73
+ ```ruby
74
+ require 'jagram'
75
+
76
+ 結果 = ""
77
+ 1.から(4, まで繰り返す) do |i|
78
+ 結果 += i.を文字に変換
79
+ end
80
+ 次を表示(結果) #> 1234
81
+
82
+ 結果 = ""
83
+ 4.から(1, まで繰り返す) do |i|
84
+ 結果 += i.を文字に変換
85
+ end
86
+ 次を表示(結果) #> 4321
87
+ ```
88
+ #### n回繰り返す構文 - times文に相当
89
+ ```ruby
90
+ require 'jagram'
91
+ 3.回繰り返す do |i|
92
+  次を表示("#{i}回目のこんにちは") #> 1回目のこんにちは, 2回目のこんにちは, 3回目のこんにちは
93
+ end
94
+ ```
95
+
96
+ #### 配列のそれぞれの要素を繰り返す - each文に相当
97
+
98
+ ```ruby
99
+ require 'jagram'
100
+ 挨拶の配列 = ["こ", "ん", "に", "ち", "は"]
101
+ 挨拶の配列.のそれぞれの要素に対して do |要素|
102
+ 次を表示(要素) #> こ ん に ち は
103
+ end
104
+ ```
105
+ ### 条件分岐構文
106
+
107
+ #### 条件が等しいとき
108
+ ```ruby
109
+ require 'jagram'
110
+ 太郎君の挨拶 = "hello"
111
+ 英語の挨拶 = "hello"
112
+ もし(太郎君の挨拶.は次と等しい(英語の挨拶), ならば) {
113
+ 次を表示("太郎君は英語がわかるのかもしれない")
114
+ }
115
+ もし(太郎君の挨拶 == 英語の挨拶, ならば) {
116
+ 次を表示("太郎君は英語がわかるのかもしれない")
117
+ }
118
+ ```
119
+
120
+ #### 大小を比較する場合
121
+
122
+ ```ruby
123
+ ## 大きい場合
124
+ require 'jagram'
125
+ 太郎君の体重 = 60
126
+ 花子さんの体重 = 120
127
+
128
+ もし(花子さんの体重.は次の値以上(太郎君の体重), ならば) {
129
+ 次を表示("花子さんは太郎君よりも#{花子さんの体重 / 太郎君の体重}倍重たい") #> 花子さんは太郎君よりも2.0倍重たい
130
+ }
131
+
132
+ もし(花子さんの体重 >= 太郎君の体重, ならば) {
133
+ 次を表示("花子さんは太郎君よりも#{花子さんの体重 / 太郎君の体重}倍重たい") #> 花子さんは太郎君よりも2.0倍重たい
134
+ }
135
+
136
+ もし(花子さんの体重.は次の値より大きい(太郎君の体重), ならば) {
137
+ 次を表示("花子さんは太郎君よりも#{花子さんの体重 / 太郎君の体重}倍重たい") #> 花子さんは太郎君よりも2.0倍重たい
138
+ }
139
+
140
+ もし(花子さんの体重 > 太郎君の体重, ならば) {
141
+ 次を表示("花子さんは太郎君よりも#{花子さんの体重 / 太郎君の体重}倍重たい") #> 花子さんは太郎君よりも2.0倍重たい
142
+ }
143
+
144
+ ## 小さい場合
145
+ 太郎君の体重 = 60
146
+ 花子さんの体重 = 120
147
+
148
+ もし(太郎君の体重.は次の値以下(花子さんの体重), ならば) {
149
+ 次を表示("太郎君は花子さんより軽い") #> 太郎君は花子さんより軽い
150
+ }
151
+
152
+ もし(太郎君の体重 <= 花子さんの体重, ならば) {
153
+ 次を表示("太郎君は花子さんより軽い") #> 太郎君は花子さんより軽い
154
+ }
155
+
156
+ もし(太郎君の体重.は次の値より小さい(花子さんの体重), ならば) {
157
+ 次を表示("太郎君は花子さんより軽い") #> 太郎君は花子さんより軽い
158
+ }
159
+
160
+ もし(太郎君の体重 < 花子さんの体重, ならば) {
161
+ 次を表示("太郎君は花子さんより軽い") #> 太郎君は花子さんより軽い
162
+ }
163
+ ```
164
+ ### 関数の作成構文
165
+
166
+ ```ruby
167
+ require 'jagram'
168
+ 関数 :挨拶する, を定義する, -> (挨拶) {
169
+ 次を表示(挨拶)
170
+ }
171
+
172
+ 挨拶する("こんにちは") #> こんにちは
173
+ 挨拶する("hello") #> hello
174
+
175
+ 関数 :国に応じた挨拶, を定義する, -> (国) {
176
+ 使った挨拶 = ""
177
+ もし(国 == "アメリカ", ならば) {
178
+ 次を表示("Hello")
179
+ 使った挨拶 = "Hello"
180
+ }
181
+
182
+ もし(国 == "日本", ならば) {
183
+ 次を表示("こんにちは")
184
+ 使った挨拶 = "こんにちは"
185
+ }
186
+
187
+ もし(国 == "中国", ならば) {
188
+ 次を表示("ニイハオ")
189
+ 使った挨拶 = "ニイハオ"
190
+ }
191
+ 使った挨拶
192
+ }
193
+
194
+ 国に応じた挨拶("アメリカ") #> Hello
195
+ 国に応じた挨拶("日本") #> こんにちは
196
+ 国に応じた挨拶("ニイハオ") #> ニイハオ
197
+ ```
198
+
199
+ ## Development
200
+
201
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
202
+
203
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
204
+
205
+ ## Contributing
206
+
207
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/jagram. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/[USERNAME]/jagram/blob/master/CODE_OF_CONDUCT.md).
208
+
209
+ ## License
210
+
211
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
212
+
213
+ ## Code of Conduct
214
+
215
+ Everyone interacting in the Jagram project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/jagram/blob/master/CODE_OF_CONDUCT.md).
data/Rakefile ADDED
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "rspec/core/rake_task"
5
+
6
+ RSpec::Core::RakeTask.new(:spec)
7
+
8
+ task default: :spec
data/bin/console ADDED
@@ -0,0 +1,15 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require "bundler/setup"
5
+ require "jagram"
6
+
7
+ # You can add fixtures and/or initialization code here to make experimenting
8
+ # with your gem easier. You can also use a different console, if you like.
9
+
10
+ # (If you use this, don't forget to add pry to your Gemfile!)
11
+ # require "pry"
12
+ # Pry.start
13
+
14
+ require "irb"
15
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
data/jagram.gemspec ADDED
@@ -0,0 +1,35 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "lib/jagram/version"
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "jagram"
7
+ spec.version = Jagram::VERSION
8
+ spec.authors = ["samurait"]
9
+ spec.email = ["t.yasukawa01@gmail.com"]
10
+
11
+ spec.summary = "jagram is JApanese proGRAMming language"
12
+ spec.description = "jagram is made for japanese programming eduction purpose"
13
+ spec.homepage = 'https://rubygems.org/gems/jagram'
14
+ spec.license = "MIT"
15
+ spec.required_ruby_version = Gem::Requirement.new(">= 2.4.0")
16
+
17
+ spec.metadata["homepage_uri"] = spec.homepage
18
+ spec.metadata["source_code_uri"] = "https://github.com/SamuraiT/jagram"
19
+ spec.metadata["changelog_uri"] = "https://github.com/SamuraiT/jagram/CHANGELOG.md"
20
+
21
+ # Specify which files should be added to the gem when it is released.
22
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
23
+ spec.files = Dir.chdir(File.expand_path(__dir__)) do
24
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{\A(?:test|spec|features)/}) }
25
+ end
26
+ spec.bindir = "exe"
27
+ spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
28
+ spec.require_paths = ["lib"]
29
+
30
+ # Uncomment to register a new dependency of your gem
31
+ # spec.add_dependency "example-gem", "~> 1.0"
32
+
33
+ # For more information and examples about making a new gem, checkout our
34
+ # guide at: https://bundler.io/guides/creating_gem.html
35
+ end
@@ -0,0 +1,138 @@
1
+
2
+ module Jagram::ConditionalStatement
3
+
4
+ # 条件分岐 - もし
5
+ #
6
+ # 引数に渡した条件が条件が真のときに、
7
+ # `{}`や`do .. end`で囲んだ処理を実行します。
8
+ # 「ならば」は省略可能です。
9
+ #
10
+ # @example 条件分岐の使い方 - `{}`を使った`もし`の例
11
+ # i = 0
12
+ # もし( i == 0, ならば) {
13
+ # 次を表示("iは0です") #> iは0です
14
+ # }
15
+ # もし( i == 0) { # ちなみに、ならばは省略可能
16
+ # 次を表示("iは0です") #> iは0です
17
+ # }
18
+ #
19
+ # @example もしの活用 - 条件が等しいときの例
20
+ # 太郎君の挨拶 = "hello"
21
+ # 英語の挨拶 = "hello"
22
+ # もし(太郎君の挨拶.は次と等しい(英語の挨拶), ならば) {
23
+ # 次を表示("太郎君は英語がわかるのかもしれない")
24
+ # }
25
+ # もし(太郎君の挨拶 == 英語の挨拶, ならば) {
26
+ # 次を表示("太郎君は英語がわかるのかもしれない")
27
+ # }
28
+ #
29
+ # @example もしの活用 - 条件が等しくないときの例
30
+ # 英語の挨拶 = "hello"
31
+ # 太郎君の挨拶 = "こんにちは"
32
+ # もし(太郎君の挨拶.は次と等しくない(英語の挨拶), ならば) {
33
+ # 次を表示("英語がわからないのかもしれない")
34
+ # }
35
+ # もし(太郎君の挨拶 != 英語の挨拶, ならば) {
36
+ # 次を表示("英語がわからないのかもしれない")
37
+ # }
38
+ #
39
+ # @example もしの活用 - 数字の比較 - 以上, より大きい
40
+ # 太郎君の体重 = 60
41
+ # 花子さんの体重 = 120
42
+ #
43
+ # もし(花子さんの体重.は次の値以上(太郎君の体重), ならば) {
44
+ # 次を表示("花子さんは太郎君よりも#{花子さんの体重 / 太郎君の体重}倍重たい") #> 花子さんは太郎君よりも2.0倍重たい
45
+ # }
46
+ #
47
+ # もし(花子さんの体重 >= 太郎君の体重, ならば) {
48
+ # 次を表示("花子さんは太郎君よりも#{花子さんの体重 / 太郎君の体重}倍重たい") #> 花子さんは太郎君よりも2.0倍重たい
49
+ # }
50
+ #
51
+ # もし(花子さんの体重.は次の値より大きい(太郎君の体重), ならば) {
52
+ # 次を表示("花子さんは太郎君よりも#{花子さんの体重 / 太郎君の体重}倍重たい") #> 花子さんは太郎君よりも2.0倍重たい
53
+ # }
54
+ #
55
+ # もし(花子さんの体重 > 太郎君の体重, ならば) {
56
+ # 次を表示("花子さんは太郎君よりも#{花子さんの体重 / 太郎君の体重}倍重たい") #> 花子さんは太郎君よりも2.0倍重たい
57
+ # }
58
+ #
59
+ # @example もしの活用 - 数字の比較 - 以下, より小さい
60
+ # 太郎君の体重 = 60
61
+ # 花子さんの体重 = 120
62
+ #
63
+ # もし(太郎君の体重.は次の値以下(花子さんの体重), ならば) {
64
+ # 次を表示("太郎君は花子さんより軽い") #> 太郎君は花子さんより軽い
65
+ # }
66
+ #
67
+ # もし(太郎君の体重 <= 花子さんの体重, ならば) {
68
+ # 次を表示("太郎君は花子さんより軽い") #> 太郎君は花子さんより軽い
69
+ # }
70
+ #
71
+ # もし(太郎君の体重.は次の値より小さい(花子さんの体重), ならば) {
72
+ # 次を表示("太郎君は花子さんより軽い") #> 太郎君は花子さんより軽い
73
+ # }
74
+ #
75
+ # もし(太郎君の体重 < 花子さんの体重, ならば) {
76
+ # 次を表示("太郎君は花子さんより軽い") #> 太郎君は花子さんより軽い
77
+ # }
78
+ #
79
+ # @param cond [Boolean] 条件
80
+ # @param block [Proc] もし条件が真であった場合に、渡したブロックを実行する
81
+ def もし(cond, cmd=ならば, &block)
82
+ if cond
83
+ block.call
84
+ end
85
+ end
86
+
87
+ # @!visibility private
88
+ def ならば
89
+ :then
90
+ end
91
+
92
+ # @!visibility private
93
+ def は次と等しくない(x)
94
+ self == x
95
+ end
96
+ # @!visibility private
97
+ def は次と等しい(x)
98
+ self == x
99
+ end
100
+
101
+ # @!visibility private
102
+ def は次の値以上(x)
103
+ self >= x
104
+ end
105
+
106
+ # @!visibility private
107
+ def は次の値以下(x)
108
+ self <= x
109
+ end
110
+
111
+ # @!visibility private
112
+ def は次の値より大きい(x)
113
+ self > x
114
+ end
115
+
116
+ # @!visibility private
117
+ def は次の値より小さい(x)
118
+ self < x
119
+ end
120
+
121
+ # @!visibility private
122
+ def は(val, cmd_type)
123
+ case cmd_type
124
+ when :eq_gte
125
+ self >= val
126
+ when :eq_lt
127
+ self <= val
128
+ when :gte
129
+ self > val
130
+ when :lt
131
+ self < val
132
+ when :eq
133
+ self == val
134
+ when :not_eq
135
+ self != val
136
+ end
137
+ end
138
+ end
@@ -0,0 +1,52 @@
1
+ module Jagram::FunctionStatement
2
+
3
+ # 関数の定義
4
+ #
5
+ # 「関数」を利用することで、関数を定義して、
6
+ # 後から呼び出して使うことができます。
7
+ #
8
+ # @example 使い方 - 関数の定義・定義した関数の利用の仕方
9
+ # 関数 :挨拶する, を定義する, -> (挨拶) {
10
+ # 次を表示(挨拶)
11
+ # }
12
+ #
13
+ # 挨拶する("こんにちは") #> こんにちは
14
+ # 挨拶する("hello") #> hello
15
+ #
16
+ # @example 使い方 - 関数の定義・定義した関数の利用の仕方
17
+ # 関数 :国に応じた挨拶, を定義する, -> (国) {
18
+ # 使った挨拶 = ""
19
+ # もし(国 == "アメリカ", ならば) {
20
+ # 次を表示("Hello")
21
+ # 使った挨拶 = "Hello"
22
+ # }
23
+ #
24
+ # もし(国 == "日本", ならば) {
25
+ # 次を表示("こんにちは")
26
+ # 使った挨拶 = "こんにちは"
27
+ # }
28
+ #
29
+ # もし(国 == "中国", ならば) {
30
+ # 次を表示("ニイハオ")
31
+ # 使った挨拶 = "ニイハオ"
32
+ # }
33
+ # 使った挨拶
34
+ # }
35
+ #
36
+ # 国に応じた挨拶("アメリカ") #> Hello
37
+ # 国に応じた挨拶("日本") #> こんにちは
38
+ # 国に応じた挨拶("ニイハオ") #> ニイハオ
39
+ #
40
+ # @param func_name [String, Symbol] 関数名
41
+ # @param cmd_type [Symbol] 関数の定義名
42
+ # @param block [Proc]
43
+ def 関数(func_name, cmd_type=を定義する, block)
44
+ raise if cmd_type != :define_jp_function
45
+ send(:define_method, func_name, block)
46
+ end
47
+
48
+ # @!visibility private
49
+ def を定義する
50
+ :define_jp_function
51
+ end
52
+ end
@@ -0,0 +1,153 @@
1
+ module Jagram::LoopStatement
2
+ class LoopStatementBreak < Exception
3
+ end
4
+ # 繰り返し構文 (while 文)
5
+ #
6
+ # @example 使い方- 繰り返し構文の利用例
7
+ # i = 0
8
+ # 次の条件が成り立つ間( -> { i <= 5} ) do
9
+ # 次を表示する(i) #> 0,1,2,3,4,5
10
+ # i += 1
11
+ # end
12
+ #
13
+ # i = 0
14
+ # 結果 = ""
15
+ # 次の条件が成り立つ間(-> {i <= 5}) {
16
+ # 結果 += i.を文字に変換
17
+ # i += 1
18
+ # }
19
+ # 次を表示する(結果) #> 012345
20
+ # expect(結果).to eq("012345")
21
+ # @param cond_func [Proc] 条件
22
+ # @param block [Proc] do..endで挟むブロック
23
+ # @return [nil]
24
+ #
25
+ def 次の条件が成り立つ間(cond_func, &block)
26
+ while cond_func.call
27
+ yield
28
+ 次の条件が成り立つ間(cond_func, &block)
29
+ end
30
+ end
31
+
32
+ # 繰り返し構文 (Loop 文)
33
+ #
34
+ # @example 使い方- 繰り返し構文の利用例
35
+ # i = 0
36
+ # 次を繰り返す {
37
+ # もし(i.は, 0, ならば) do
38
+ # 繰り返しから抜ける
39
+ # end
40
+ # 次を表示する(i) #> 0,1,2,3,4,5
41
+ # i += 1
42
+ # }
43
+ #
44
+ #
45
+ # @example 使い方2- 繰り返し構文の利用例(doとendを使う場合)
46
+ # i = 0
47
+ # 次を繰り返す do
48
+ # もし(i.は, 0, ならば) do
49
+ # 繰り返しから抜ける
50
+ # end
51
+ # 次を表示する(i) #> 0,1,2,3,4,5
52
+ # i += 1
53
+ # end
54
+ # @param block [Proc] do..endで挟むブロック
55
+ # @return [nil]
56
+ def 次を繰り返す(&block)
57
+ while true
58
+ block.call
59
+ end
60
+ rescue LoopStatementBreak
61
+ end
62
+
63
+ # 繰り返しから抜け出すための制御文
64
+ #
65
+ # 繰り返し構文を使っていて、
66
+ # 繰り返し構文から抜けたいときに利用します。
67
+ #
68
+ # @example 使い方- 繰り返しから抜ける の利用例
69
+ # i = 0
70
+ # 次を繰り返す do
71
+ # もし( i > 5 ) do
72
+ # 繰り返しから抜ける # これを呼び出すことで、iが5よりも大きいときに繰り返しを抜け出す
73
+ # end
74
+ # 次を表示する(i) #> 0,1,2,3,4,5
75
+ # i += 1
76
+ # end
77
+ # @return [nil]
78
+ def 繰り返しから抜ける
79
+ raise LoopStatementBreak
80
+ end
81
+
82
+ # @!visibility private
83
+ def まで繰り返す
84
+ :loop_until
85
+ end
86
+ module IntegerMethod
87
+ # 繰り返し構文
88
+ # `n.回繰り返す`とすることで, nの数値に応じた回数を
89
+ # 繰り返すことが可能です。
90
+ #
91
+ # @example 使い方 - 回繰り返すの使い方
92
+ # 3.回繰り返す do
93
+ # 次を表示("こんにちは") #> こんにちは, こんにちは, こんにちは
94
+ # end
95
+ # @example 使い方 - 回繰り返すの使い方
96
+ # 3.回繰り返す do |i|
97
+ #  次を表示("#{i}回目のこんにちは") #> 1回目のこんにちは, 2回目のこんにちは, 3回目のこんにちは
98
+ # end
99
+ # @param [Proc]
100
+ def 回繰り返す(&block)
101
+ for i in 1..self
102
+ yield i
103
+ end
104
+ end
105
+
106
+ # 繰り返し構文
107
+ #
108
+ # n.から(m, まで繰り返す) とすることで、nからmまでを繰り返すことが可能です。
109
+ #
110
+ # @example 使い方 - から を使った繰り返し構文
111
+ # 1.から(3, まで繰り返す) do
112
+ #  次を表示("こんにちは") #> こんにちは, こんにちは, こんにちは
113
+ # end
114
+ #
115
+ # # do |変数名|とすることで数値を取り出すことも可能です
116
+ # 1.から(3, まで繰り返す) do |i|
117
+ #  次を表示("#{i}回目のこんにちは") #> 1回目のこんにちは, 2回目のこんにちは, 3回目のこんにちは
118
+ # end
119
+ #
120
+ # @example 使い方 - から を使った繰り返し構文2
121
+ # # do |変数名|とすることで数値を取り出すことも可能です
122
+ # 1.から(3, まで繰り返す) do |i|
123
+ #  次を表示(i) #> 1,2,3
124
+ # end
125
+ # @example 使い方 - から を使った繰り返し構文 大きい数字から小さい数値
126
+ # # do |変数名|とすることで数値を取り出すことも可能です
127
+ # 結果 = ""
128
+ # 1.から(4, まで繰り返す) do |i|
129
+ # 結果 += i.を文字に変換
130
+ # end
131
+ # 次を表示(結果) #> 1234
132
+ #
133
+ # 結果 = ""
134
+ # 4.から(1, まで繰り返す) do |i|
135
+ # 結果 += i.を文字に変換
136
+ # end
137
+ # 次を表示(結果) #> 4321
138
+ def から(last, cmd_type=まで繰り返す, &block)
139
+ if last >= self
140
+ for i in self..last
141
+ yield i
142
+ end
143
+ else
144
+ i = self
145
+ while i >= last
146
+ yield i
147
+ i -= 1
148
+ end
149
+ end
150
+ end
151
+ end
152
+ end
153
+
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Jagram
4
+ VERSION = "0.1.0"
5
+
6
+ end
data/lib/jagram.rb ADDED
@@ -0,0 +1,88 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "jagram/version"
4
+ require_relative "jagram/loop"
5
+ require_relative "jagram/conditional"
6
+ require_relative "jagram/function"
7
+
8
+ class Array
9
+ # 配列のそれぞれの要素を取り出せる繰り返し文
10
+ #
11
+ # @example
12
+ # 挨拶の配列 = ["こ", "ん", "に", "ち", "は"]
13
+ # 挨拶の配列.のそれぞれの要素に対して do |要素|
14
+ # 次を表示(要素) #> こ ん に ち は
15
+ # end
16
+ #  数値の配列 = [1,2,3]
17
+ # 数値の配列.のそれぞれの要素に対して do |i|
18
+ # 次を表示(i) #> 1,2,3
19
+ # end
20
+ #
21
+ # @param [Proc]
22
+ # @return [self]
23
+ def のそれぞれの要素に対して(&block)
24
+ i = 0
25
+ size = self.length
26
+ while size > i
27
+ yield self[i]
28
+ i += 1
29
+ end
30
+ self
31
+ end
32
+
33
+ # 配列の長さを返す関数 
34
+ # @example
35
+ # t = [1,2,3]
36
+ # t.長さ #> 3
37
+ # @return [Integer] 配列の長さを返す
38
+ def 長さ
39
+ self.length
40
+ end
41
+
42
+ end
43
+
44
+
45
+ class Object
46
+ include Jagram::LoopStatement
47
+ # @!parse include LoopStatement
48
+
49
+ include Jagram::ConditionalStatement
50
+ # @!parse include ConditionalStatement
51
+
52
+ include Jagram::FunctionStatement
53
+ # @!parse include FunctionStatement
54
+
55
+ # 引数をそのまま標準出力に表示するメソッド
56
+ # 使用例
57
+ #
58
+ # @example 使い方 - 文字列を表示する方法
59
+ # 次を表示("こんにちは") #> こんにちは
60
+ # 朝の挨拶 = "おはよう"
61
+ # 次を表示("朝の挨拶は「#{朝の挨拶}」です") #> 朝の挨拶は「おはよう」です
62
+ #
63
+ # @example 使い方 - 数値を表示する方法
64
+ # 次を表示(1234) #> 1234
65
+ # お昼の時間 = 12
66
+ # 次を表示(お昼の時間) #> 12
67
+ #
68
+ # @param arg [Object] 標準出力に表示させたいオブジェクト
69
+ # @return [nil] 返り値はない。標準出力に表示するだけ
70
+ def 次を表示(arg)
71
+ puts arg
72
+ end
73
+
74
+ end
75
+
76
+ class String
77
+ def を数値に変換
78
+ self.to_i
79
+ end
80
+ end
81
+
82
+ class Integer
83
+ include Jagram::LoopStatement::IntegerMethod
84
+ def を文字に変換
85
+ self.to_s
86
+ end
87
+ end
88
+
metadata ADDED
@@ -0,0 +1,64 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: jagram
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - samurait
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2021-11-23 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: jagram is made for japanese programming eduction purpose
14
+ email:
15
+ - t.yasukawa01@gmail.com
16
+ executables: []
17
+ extensions: []
18
+ extra_rdoc_files: []
19
+ files:
20
+ - ".github/workflows/main.yml"
21
+ - ".gitignore"
22
+ - ".rspec"
23
+ - CHANGELOG.md
24
+ - CODE_OF_CONDUCT.md
25
+ - Gemfile
26
+ - Gemfile.lock
27
+ - LICENSE.txt
28
+ - README.md
29
+ - Rakefile
30
+ - bin/console
31
+ - bin/setup
32
+ - jagram.gemspec
33
+ - lib/jagram.rb
34
+ - lib/jagram/conditional.rb
35
+ - lib/jagram/function.rb
36
+ - lib/jagram/loop.rb
37
+ - lib/jagram/version.rb
38
+ homepage: https://rubygems.org/gems/jagram
39
+ licenses:
40
+ - MIT
41
+ metadata:
42
+ homepage_uri: https://rubygems.org/gems/jagram
43
+ source_code_uri: https://github.com/SamuraiT/jagram
44
+ changelog_uri: https://github.com/SamuraiT/jagram/CHANGELOG.md
45
+ post_install_message:
46
+ rdoc_options: []
47
+ require_paths:
48
+ - lib
49
+ required_ruby_version: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - ">="
52
+ - !ruby/object:Gem::Version
53
+ version: 2.4.0
54
+ required_rubygems_version: !ruby/object:Gem::Requirement
55
+ requirements:
56
+ - - ">="
57
+ - !ruby/object:Gem::Version
58
+ version: '0'
59
+ requirements: []
60
+ rubygems_version: 3.1.4
61
+ signing_key:
62
+ specification_version: 4
63
+ summary: jagram is JApanese proGRAMming language
64
+ test_files: []