Top Level Namespace
Defined Under Namespace
Modules: Dsl Classes: ANSI, Array, FalseClass, Hash, Integer, NilClass, String, TrueClass
Constant Summary collapse
- None =
nil- True =
true- False =
false
Instance Method Summary collapse
- #bye ⇒ Object
- #copyright ⇒ Object
- #credits ⇒ Object
- #float(obj) ⇒ Object
- #id(obj) ⇒ Object
- #import(filename) ⇒ Object
- #int(obj) ⇒ Object
- #len(obj) ⇒ Object
- #license ⇒ Object
- #list(obj) ⇒ Object
- #print(*args) ⇒ Object
- #range(value) ⇒ Object
- #run_program(filepath) ⇒ Object
- #str(obj) ⇒ Object
- #that ⇒ Object
- #this ⇒ Object
- #type(x) ⇒ Object
- #version ⇒ Object
- #whereareyou ⇒ Object
- #whoareyou ⇒ Object
- #zen ⇒ Object
Instance Method Details
#bye ⇒ Object
18 19 20 21 22 23 |
# File 'lib/dsl/python/repl/etc.rb', line 18 def bye puts "" system("figlet 'I love Ruby'") puts "" exit end |
#copyright ⇒ Object
3 4 5 6 7 8 9 10 |
# File 'lib/dsl/python/repl/copyright.rb', line 3 def copyright text = <<~TEXT Copyright (c) 2025-2025 nPython Software Foundation. All Rights Reserved. TEXT puts text "(Copyright)" end |
#credits ⇒ Object
3 4 5 6 7 8 9 10 |
# File 'lib/dsl/python/repl/credits.rb', line 3 def credits text = <<~TEXT Thanks to Free Software, Yukuhiro Matzumoto, David Vargas Ruiz and a cast of thousands for supporting nPython development. See 'github.com/dvarrui/dsl-python' for more information. TEXT puts text end |
#float(obj) ⇒ Object
20 |
# File 'lib/dsl/python/functions/type.rb', line 20 def float(obj) = obj.to_f |
#id(obj) ⇒ Object
13 14 15 |
# File 'lib/dsl/python/functions/etc.rb', line 13 def id(obj) obj.object_id end |
#import(filename) ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/dsl/python/functions/import.rb', line 7 def import(filename) filename.to_s dirbase = File.dirname($main_filepath) filepath = File.join(dirbase, filename + ".py") if filename.to_s == "this" Dsl::Python.show_zen elsif filename.to_s == "that" Dsl::Python.show_zen(ofuscate: true) elsif File.exist? filepath content = File.read(filepath) eval(content, $main_binding) else puts "npython: can't open file '#{filepath}': [Errno 2] No such file or directory" end end |
#int(obj) ⇒ Object
21 |
# File 'lib/dsl/python/functions/type.rb', line 21 def int(obj) = obj.to_i |
#len(obj) ⇒ Object
1 2 3 4 5 6 7 8 9 10 11 |
# File 'lib/dsl/python/functions/etc.rb', line 1 def len(obj) if obj.respond_to?(:length) obj.length elsif obj.respond_to?(:count) obj.count elsif obj.respond_to?(:size) obj.size else puts "TypeError: object of type '#{type(obj)}' has no len()" end end |
#license ⇒ Object
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/dsl/python/repl/license.rb', line 3 def license text = <<~TEXT nPython is copyrighted free software by David Vargas Ruiz <dvarrui@proton.me>. You can redistribute it and/or modify it under either the terms of the 2-clause BSDL (see the file BSDL), or the conditions below: 1. You may make and give away verbatim copies of the source form of the software without restriction, provided that you duplicate all of the original copyright notices and associated disclaimers. 2. You may modify your copy of the software in any way, provided that you do at least ONE of the following: a) place your modifications in the Public Domain or otherwise make them Freely Available, such as by posting said modifications to Usenet or an equivalent medium, or by allowing the author to include your modifications in the software. b) use the modified software only within your corporation or organization. c) give non-standard binaries non-standard names, with instructions on where to get the original software distribution. d) make other distribution arrangements with the author. 3. You may distribute the software in object code or binary form, provided that you do at least ONE of the following: a) distribute the binaries and library files of the software, together with instructions (in the manual page or equivalent) on where to get the original distribution. b) accompany the distribution with the machine-readable source of the software. c) give non-standard binaries non-standard names, with instructions on where to get the original software distribution. d) make other distribution arrangements with the author. 4. You may modify and include the part of the software into any other software (possibly commercial). But some files in the distribution are not written by the author, so that they are not under these terms. For the list of those files and their copying conditions, see the file LEGAL. 5. The scripts and library files supplied as input to or produced as output from the software do not automatically fall under the copyright of the software, but belong to whomever generated them, and may be sold commercially, and may be aggregated with this software. 6. THIS SOFTWARE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. TEXT puts text "(License)" end |
#list(obj) ⇒ Object
23 |
# File 'lib/dsl/python/functions/type.rb', line 23 def list(obj) = obj.to_a |
#print(*args) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/dsl/python.rb', line 23 def print(*args) if args.is_a? Array if args.count == 1 puts args.first else puts args.join " " end else puts(args) end end |
#range(value) ⇒ Object
3 4 5 |
# File 'lib/dsl/python/types/range.rb', line 3 def range(value) Range.new(0, value - 1) end |
#run_program(filepath) ⇒ Object
36 37 38 39 40 41 42 43 44 45 |
# File 'lib/dsl/python/cli.rb', line 36 def run_program(filepath) unless File.exist? filepath puts "npython: can't open file '#{filepath}': [Errno 2] No such file or directory" exit 1 end $main_filepath = filepath content = File.read(filepath) eval(content) end |
#str(obj) ⇒ Object
22 |
# File 'lib/dsl/python/functions/type.rb', line 22 def str(obj) = obj.to_s |
#that ⇒ Object
9 10 11 |
# File 'lib/dsl/python/repl/zen.rb', line 9 def that "that" end |
#this ⇒ Object
5 6 7 |
# File 'lib/dsl/python/repl/zen.rb', line 5 def this "this" end |
#type(x) ⇒ Object
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
# File 'lib/dsl/python/functions/type.rb', line 3 def type(x) key = x.class.to_s.to_sym types = { Array: "list", FalseClass: "bool", Float: "float", Hash: "dict", Integer: "int", NilClass: "NoneType", Range: "range", String: "str", TrueClass: "bool" } "<class '#{types[key]}'>" end |
#version ⇒ Object
9 10 11 12 |
# File 'lib/dsl/python/version.rb', line 9 def version puts Dsl::Python::VERSION "(Version)" end |
#whereareyou ⇒ Object
10 11 12 13 14 15 16 |
# File 'lib/dsl/python/repl/etc.rb', line 10 def whereareyou text = ANSI.new.green("https://github.com/dvarrui/dsl-python") puts " You can find me at: #{text}" text = ANSI.new.green("https://rubygems.org/gems/dsl-python") puts " And also at: #{text}" nil end |