Class: String
- Inherits:
-
Object
- Object
- String
- Defined in:
- lib/javaclass/string_ux.rb,
lib/javaclass/java_name.rb
Overview
Add some unpack
helper methods for HI-LO byte order (network byte order) contained in this string.
- Author
-
Peter Kofler
Direct Known Subclasses
Instance Method Summary collapse
-
#double(index = 0) ⇒ Object
Return the index’th and the next 7 elements as double precision float.
-
#single(index = 0) ⇒ Object
Return the index’th and the next 3 elements as single precision float.
-
#to_javaname ⇒ Object
Convert a Java classname or Java class filename to JavaClass::JavaName instance.
-
#u1(index = 0) ⇒ Object
Return the index’th element as byte.
-
#u2(index = 0) ⇒ Object
Return the index’th and the next element as unsigned word.
-
#u4(index = 0) ⇒ Object
Return the index’th and the next 3 elements as unsigned dword.
-
#u8(index = 0) ⇒ Object
Return the index’th and the next 7 elements as unsigned qword.
Instance Method Details
#double(index = 0) ⇒ Object
Return the index’th and the next 7 elements as double precision float.
35 36 37 |
# File 'lib/javaclass/string_ux.rb', line 35 def double(index=0) self[index..index+7].unpack('G')[0] end |
#single(index = 0) ⇒ Object
Return the index’th and the next 3 elements as single precision float.
30 31 32 |
# File 'lib/javaclass/string_ux.rb', line 30 def single(index=0) self[index..index+3].unpack('g')[0] end |
#to_javaname ⇒ Object
Convert a Java classname or Java class filename to JavaClass::JavaName instance. If it’s a pathname then it must be relative to the classpath.
86 87 88 |
# File 'lib/javaclass/java_name.rb', line 86 def to_javaname JavaClass::JavaName.new(self) end |
#u1(index = 0) ⇒ Object
Return the index’th element as byte.
7 8 9 |
# File 'lib/javaclass/string_ux.rb', line 7 def u1(index=0) self[index] end |
#u2(index = 0) ⇒ Object
Return the index’th and the next element as unsigned word.
12 13 14 15 |
# File 'lib/javaclass/string_ux.rb', line 12 def u2(index=0) self[index..index+1].unpack('n')[0] # same as self[index]*256 + self[index+1] end |
#u4(index = 0) ⇒ Object
Return the index’th and the next 3 elements as unsigned dword.
18 19 20 |
# File 'lib/javaclass/string_ux.rb', line 18 def u4(index=0) self[index..index+3].unpack('N')[0] end |
#u8(index = 0) ⇒ Object
Return the index’th and the next 7 elements as unsigned qword.
23 24 25 |
# File 'lib/javaclass/string_ux.rb', line 23 def u8(index=0) u4(index) * 256**4 + u4(index+4) end |